Libraryless. Click here for Pure Java version (9445L/53K).
1 | sclass CheckerBoard2 is G2Drawable {
|
2 | settable int w = 256; |
3 | settable int h = 256; |
4 | |
5 | settable double shiftX; |
6 | settable double shiftY; |
7 | |
8 | settable double cellW = 8; |
9 | settable double cellH = 8; |
10 | |
11 | settable Color color1 = Color.lightGray; |
12 | settable Color color2 = Color.gray; |
13 | |
14 | selfType cellSize(double cellSize) {
|
15 | ret cellW(cellSize).cellH(cellSize); |
16 | } |
17 | |
18 | public int getWidth() { ret w; }
|
19 | public int getHeight() { ret h; }
|
20 | |
21 | public void drawOn(Graphics2D g) {
|
22 | int xofs = idiv_floor(shiftX, cellW); |
23 | int yofs = idiv_floor(shiftY, cellH); |
24 | double x1 = mod(shiftX, cellW)-cellW; |
25 | double y1 = mod(shiftY, cellH)-cellH; |
26 | |
27 | bool bRow = odd(yofs^xofs); |
28 | for (double y = y1; y < h; y += cellH) {
|
29 | bRow = !bRow; |
30 | bool b = bRow; |
31 | for (double x = x1; x < w; x += cellW) {
|
32 | b = !b; |
33 | g.setColor(b ? color1 : color2); |
34 | g.fill(new Rectangle2D.Double(x, y, cellW, cellH)); |
35 | } |
36 | } |
37 | } |
38 | } |
Began life as a copy of #1032072
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1035257 |
| Snippet name: | CheckerBoard2 - G2Drawable, can move around |
| Eternal ID of this version: | #1035257/5 |
| Text MD5: | 7669fd799cd151f230d13364afdcccd4 |
| Transpilation MD5: | c808ef255b21395151cd34cdbb216593 |
| Author: | stefan |
| Category: | javax / imaging |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-08-20 20:28:51 |
| Source code size: | 997 bytes / 38 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 601 / 752 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |