mouse click to redraw; key press 1, 2, 3 to change line width; press s to save image
A fork of Alignment in a grid with changing line caps by Sheng-Fen Nik Chien
xxxxxxxxxx
// make accessible to DPD 2025: Complexity I
// schien@mail.ncku.edu.tw
// recreation of demos in the book "Generative Design" (http://www.generative-gestaltung.de/1/)
// P.2.1.1
// Alignment in a grid
// based on P_2_1_1_01.pde
// interactions
// Mouse: regen
// Keys: s: save png; 1,2,3: change line caps
//
// For DPD 2023: Emergence in a grid
// schien@mail.ncku.edu.tw, 20201117
// variable adjustment
// schien@mail.ncku.edu.tw, 20230425
let tileCount = 20;
let actRandomSeed = 0;
function setup() {
createCanvas(500, 500);
strokeWeight(15);
stroke(100);
}
function draw() {
background(255);
let tileWidth = width / tileCount;
randomSeed(actRandomSeed);
for (let gridY = 0; gridY < tileCount; gridY++) {
for (let gridX = 0; gridX < tileCount; gridX++) {
let posX = tileWidth * gridX;
let posY = tileWidth * gridY;
let toggle = int(random(0, 2));
if (toggle === 0) {
line(posX, posY, posX + tileWidth, posY + tileWidth);
}
if (toggle === 1) {
line(posX, posY + tileWidth, posX + tileWidth, posY);
}
}
}
}
function mousePressed() {
actRandomSeed = int(random(100000));
}
function keyPressed() {
switch (key) {
case '1':
strokeCap(ROUND);
break;
case '2':
strokeCap(SQUARE);
break;
case '3':
strokeCap(PROJECT);
break;
case 'S':
case 's':
save('diagnals.png');
break;
}
}