p5(sketch => {
let system;
let sizeScale = 150;
let widthScale = 6;
let heightScale = 8;
let canvasWidth = width
let canvasHeight = heightScale * sizeScale;
let nSquare = nSq2
let colors = [
sketch.color("#FCBC3C"),
sketch.color("#FB5444"),
sketch.color("#F68C8C"),
sketch.color("#3C4C7C"),
sketch.color("#74B4E4")
]
let squareSize = canvasWidth / (nSquare + 1);
let xMargin = squareSize / 2;
let yMargin = (canvasHeight - squareSize * nSquare) / 2;
let cutouts = ["left", "top", "right", "bottom"];
let backgroundColors = randomize([0,1,2,3,4], nSq2);
let circleColors = randomize([0,1,2,3,4], nSq2)
let backgroundCutouts = backgroundColors;
sketch.setup = function() {
sketch.createCanvas(canvasWidth, canvasHeight);
sketch.textAlign(sketch.CENTER);
sketch.textFont('sans-serif');
sketch.textStyle(sketch.BOLD);
sketch.noStroke();
sketch.rectMode(sketch.CENTER);
}
sketch.draw = function() {
sketch.background(sketch.color("#242523"));
for (let row = 0; row < nSquare; row++) {
// Row offset is yMargin + (row + 0 .5) * squareSize
// Starting squares from center, because we will also start circles from there :)
let yStart = yMargin + (row + 0.5) * squareSize;
for (let col = 0; col < nSquare; col++) {
// Setup
let colorIndex = row * nSquare + col;
let xStart = xMargin + (col + 0.5) * squareSize;
// Background
let backgroundColor = backgroundColors[colorIndex];
backgroundColor = colors[backgroundColor];
sketch.fill(backgroundColor);
sketch.rect(xStart, yStart, squareSize, squareSize);
// Circle
let circleColor = circleColors[colorIndex];
circleColor = colors[circleColor];
sketch.fill(circleColor);
let circleSize = squareSize * 0.8;
sketch.circle(xStart, yStart, circleSize);
// Cutout
let cutout = backgroundCutouts[colorIndex];
cutout = cutouts[cutout];
sketch.fill(backgroundColor);
let cutoutOffset = circleSize * 0.5;
let cutoutSlice = circleSize * 0.25;
let xCutoutPosition;
let yCutoutPosition;
let xCutoutSize;
let yCutoutSize;
if (cutout === "left") {
xCutoutPosition = -cutoutOffset;
yCutoutPosition = 0;
xCutoutSize = cutoutSlice;
yCutoutSize = circleSize;
} else if (cutout == "right") {
xCutoutPosition = +cutoutOffset;
yCutoutPosition = 0;
xCutoutSize = cutoutSlice;
yCutoutSize = circleSize;
} else if (cutout == "top") {
xCutoutPosition = 0;
yCutoutPosition = -cutoutOffset;
yCutoutSize = cutoutSlice;
xCutoutSize = circleSize;
} else if (cutout == "bottom") {
xCutoutPosition = 0;
yCutoutPosition = cutoutOffset;
yCutoutSize = cutoutSlice;
xCutoutSize = circleSize;
}
sketch.rect(
xStart + xCutoutPosition,
yStart + yCutoutPosition,
xCutoutSize,
yCutoutSize
);
}
}
sketch.noLoop();
}
})