Libraryless. Click here for Pure Java version (9445L/53K).
sclass CheckerBoard2 is G2Drawable { settable int w = 256; settable int h = 256; settable double shiftX; settable double shiftY; settable double cellW = 8; settable double cellH = 8; settable Color color1 = Color.lightGray; settable Color color2 = Color.gray; selfType cellSize(double cellSize) { ret cellW(cellSize).cellH(cellSize); } public int getWidth() { ret w; } public int getHeight() { ret h; } public void drawOn(Graphics2D g) { int xofs = idiv_floor(shiftX, cellW); int yofs = idiv_floor(shiftY, cellH); double x1 = mod(shiftX, cellW)-cellW; double y1 = mod(shiftY, cellH)-cellH; bool bRow = odd(yofs^xofs); for (double y = y1; y < h; y += cellH) { bRow = !bRow; bool b = bRow; for (double x = x1; x < w; x += cellW) { b = !b; g.setColor(b ? color1 : color2); g.fill(new Rectangle2D.Double(x, y, cellW, cellH)); } } } }
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: | 169 / 267 |
Version history: | 4 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) |