xxxxxxxxxx
//Left and Right Arrowkey to change grid size
let boundry = 100; //set boundry size
let g = 6; //set number of grid
function setup() {
createCanvas(600, 600);
frameRate(1);
}
function draw() {
background(5, 15, 30);
let w = map(mouseX, 0, width, 1, 150); //map width of square to mouseX
let r = map(mouseY, 0, height, 0, 50); //map randomness of square to mouseY
let stepY = floor((height - boundry * 2) / g); //set grid step size based on boundry size and g number (floor to prevent wierd numbers)
let stepX = floor((width - boundry * 2) / g);
for (let column = boundry; column <= height - boundry; column += stepY) { //for every column
for (let row = boundry; row <= width - boundry; row += stepX) { //draw a row
for (let i = 0; i < 6; i++) { //6 shapes drawn
let x1 = -w+random(-r, r);
let x2 = w+random(-r, r);
let x3 = w+random(-r, r);
let x4 = -w+random(-r, r);
let y1 = -w+random(-r, r);
let y2 = -w+random(-r, r);
let y3 = w+random(-r, r);
let y4 = w+random(-r, r);
push(); //draw square at location (centered)
translate(row, column); //set square center to grid point
stroke(random(255), random(20), random(100)); //colorize
if(random(1)<0.02) { //draw white to add variations
stroke(220);
}
strokeWeight(2);
noFill();
quad(x1, y1, x2, y2, x3, y3, x4, y4); //draws shape at randomized points
pop();
}
}
}
//noLoop();
//console.log(g);
}
function keyPressed() {
if (keyIsDown(LEFT_ARROW) == true) {
if (g > 1) {
g--;
}
}
if (keyIsDown(RIGHT_ARROW) == true) {
g++;
}
}
// function mousePressed() {
// save("Week1Sub.png");
// }