1 | function setPixel(x, y, pix) |
2 | if x >= 0 and y >= 0 and x < w and y < h then |
3 | pixels[y*w+x+1] = pix |
4 | end |
5 | end |
6 | |
7 | i, j, x1, y1, x2, y2 = string.find(result, "(%d+),%s*(%d+),%s*(%d+),%s*(%d+)") |
8 | |
9 | -- copy image |
10 | |
11 | w, h = img.width, img.height |
12 | pixels = {} |
13 | for y = 0, h-1 do |
14 | for x = 0, w-1 do |
15 | pixels[y*w+x+1] = img.getInt(x, y) |
16 | end |
17 | end |
18 | |
19 | -- paint rectangle |
20 | |
21 | x1, y1 = x1-1, y1-1 -- paint AROUND the found image |
22 | x2, y2 = tonumber(x2), tonumber(y2) |
23 | |
24 | for y = y1, y2 do |
25 | setPixel(x1, y, 0xFF0000) |
26 | setPixel(x2, y, 0xFF0000) |
27 | end |
28 | |
29 | for x = x1, x2 do |
30 | setPixel(x, y1, 0xFF0000) |
31 | setPixel(x, y2, 0xFF0000) |
32 | end |
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
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 |
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: | 1723 / 192 |
Referenced in: | [show references] |