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

32
LINES

< > BotCompany Repo | #365 // Rectangle Visualizer

Lua code - Visualizer

function setPixel(x, y, pix)
  if x >= 0 and y >= 0 and x < w and y < h then
    pixels[y*w+x+1] = pix
  end
end

i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)")

-- copy image

w, h = img.width, img.height
pixels = {}
for y = 0, h-1 do
  for x = 0, w-1 do
    pixels[y*w+x+1] = img.getInt(x, y)
  end
end

-- paint rectangle

x1, y1 = x1-1, y1-1 -- paint AROUND the found image
x2, y2 = tonumber(x2), tonumber(y2)

for y = y1, y2 do
  setPixel(x1, y, 0xFF0000)
  setPixel(x2, y, 0xFF0000)
end

for x = x1, x2 do
  setPixel(x, y1, 0xFF0000)
  setPixel(x, y2, 0xFF0000)
end

Author comment

More flexible than #313

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
580 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
function setPixel(x, y, pix)
if x >= 0 and y >= 0 and x < w and y < h then
pixels[y*w+x+1] = pix
end
end

i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)")

-- copy image

w, h = img.width, img.height
pixels = {}
for y = 0, h-1 do
for x = 0, w-1 do
pixels[y*w+x+1] = img.getInt(x, y)
end
end

-- paint rectangle

x1, y1 = x1-1, y1-1 -- paint AROUND the found image
x2, y2 = tonumber(x2), tonumber(y2)

for y = y1, y2 do
setPixel(x1, y, 0xFF0000)
setPixel(x2, y, 0xFF0000)
end

for x = x1, x2 do
setPixel(x, y1, 0xFF0000)
setPixel(x, y2, 0xFF0000)
end

}}
2015-08-18 21:28:02  delete 
578 #1000604 (pitcher) 2015-08-20 15:28:24

add comment

Snippet ID: #365
Snippet name: Rectangle Visualizer
Eternal ID of this version: #365/1
Text MD5: 52b7f194aa4dbd7ec5f20606bd2dd8d6
Author: stefan
Category: ir result visualizers
Type: Lua code - Visualizer
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-02-03 21:24:36
Source code size: 636 bytes / 32 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1720 / 192
Referenced in: #367 - Multi Rectangle Visualizer
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)