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
2 comment(s) hidden. show
| 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: | 2344 / 269 |
| Referenced in: | [show references] |