xxxxxxxxxx
const CELL_SIZE = 30, CELL_CORNER_SIZE = 10;
const CELL_COLORS = ["#FE0000", "#FF7F00", "#FFCC00"];
let iniX, iniY;
let x, y, xc, yc, f, fc;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
noStroke();
iniX = random(-CELL_CORNER_SIZE, 0), iniY = random(-CELL_CORNER_SIZE, 0);
}
function draw() {
x = iniX+CELL_SIZE, y = iniY, xc = 0, yc = 0;
f = false, fc = 0;
rectMode(RADIUS);
while(y < height+CELL_CORNER_SIZE) {
while(x < width+CELL_CORNER_SIZE) {
fill(color((xc-fc)%3==0^f?"black":"white"));
square(x, y, CELL_CORNER_SIZE);
x += CELL_SIZE*2;
xc++;
}
x = iniX + (yc%2?CELL_SIZE:0);
xc = 0;
y += CELL_SIZE;
yc++;
fc += f?0:1;
f = !f;
}
x = iniX, y = iniY, xc = 0, yc = 0;
rectMode(CORNER);
while(y < height) {
while(x < width) {
const xyc = xc + yc;
const order = xyc%4==3?1:xyc%4;
fill(color(CELL_COLORS[order]));
square(x, y, CELL_SIZE,
xyc%2==1?CELL_CORNER_SIZE:0,
xyc%2==0?CELL_CORNER_SIZE:0,
xyc%2==1?CELL_CORNER_SIZE:0,
xyc%2==0?CELL_CORNER_SIZE:0
);
x += CELL_SIZE;
xc++;
}
x = iniX;
xc = 0;
y += CELL_SIZE;
yc++;
}
}