Transpiled version (2763L) is out of date.
1 | // start from center |
2 | static ItIt<Pt> pixelSpiral(int w, int h) { |
3 | ret pixelSpiral(w/2, h/2, w, h); |
4 | } |
5 | |
6 | // thanks to https://stackoverflow.com/questions/398299/looping-in-a-spiral |
7 | static ItIt<Pt> pixelSpiral(int sx, int sy, int imageWidth, int imageHeight, int maxPixels default Int.MAX_VALUE) { |
8 | ret iff_endOnNull(new F0<Pt> { |
9 | int x, y, dx, dy = -1; |
10 | int maxPixels2 = min(maxPixels, sqr(max4(sx+1, imageWidth-sx, sy+1, imageHeight-sy)*2)); |
11 | int i; |
12 | |
13 | Pt get() { |
14 | while (i++ < maxPixels2) { |
15 | int px = sx+x, py = sy+y; |
16 | |
17 | if (x == y |
18 | || x < 0 && x == -y |
19 | || x > 0 && x == 1-y) { |
20 | int t=dx; dx=-dy; dy=t; |
21 | } |
22 | x += dx; y += dy; |
23 | |
24 | if (px >= 0 && py >= 0 && px < imageWidth && py < imageHeight) |
25 | ret pt(px, py); |
26 | } |
27 | null; |
28 | } |
29 | }); |
30 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1025244 |
Snippet name: | pixelSpiral |
Eternal ID of this version: | #1025244/10 |
Text MD5: | 08a02ee11e9c109ad0ad0c955c0a5e6d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-16 17:39:10 |
Source code size: | 867 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 259 / 423 |
Version history: | 9 change(s) |
Referenced in: | [show references] |