Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #225 // GUI tester v1

Lua code

env = newCleanEnv()
gui = loadSnippet(input or "#224", env)

function step()
  local a = env.animateAgainIn
  env.pixels = nil -- so we can safely keep older pixel arrays
  if a == nil then error "Animation ended" end
  if type(a) == 'table' then
    a[2]()
  else
    gui()
  end
end

function pixelsAreEqual(a, b)
  return a == b -- We COULD account for the different pixel formats, but that case is SO unlikely to be relevant...
end

function hasMovement(old, new)
  if new == nil then return false end
  if old == nil then error "Can't evaluate" end
  local n = #old
  for i=1, n do
    if not pixelsAreEqual(old[i], new[i]) then
      return true
    end
  end
  return false
end

gui()
old = env.pixels
step()
new = env.pixels
movement = hasMovement(old, new)
print("has movement: "..tostring(movement))

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
839 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
env = newCleanEnv()
gui = loadSnippet(input or "#224", env)

function step()
local a = env.animateAgainIn
env.pixels = nil -- so we can safely keep older pixel arrays
if a == nil then error "Animation ended" end
if type(a) == 'table' then
a[2]()
else
gui()
end
end

function pixelsAreEqual(a, b)
return a == b -- We COULD account for the different pixel formats, but that case is SO unlikely to be relevant...
end

function hasMovement(old, new)
if new == nil then return false end
if old == nil then error "Can't evaluate" end
local n = #old
for i=1, n do
if not pixelsAreEqual(old[i], new[i]) then
return true
end
end
return false
end

gui()
old = env.pixels
step()
new = env.pixels
movement = hasMovement(old, new)
print("has movement: "..tostring(movement))
}}
2015-08-19 22:47:48  delete 
807 #1000604 (pitcher) 2015-08-20 15:28:24

add comment

Image recognition results

Recognizer Recognition Result Visualize Recalc
#308 844 [visualize]

Snippet ID: #225
Snippet name: GUI tester v1
Eternal ID of this version: #225/1
Text MD5: 98fb78ce843be8f9042bbeb07fb1126d
Author: stefan
Category: gui testers
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2014-02-01 22:04:17
Source code size: 844 bytes / 36 lines
Pitched / IR pitched: Yes / Yes
Views / Downloads: 1025 / 213
Referenced in: [show references]