xxxxxxxxxx
60
let rectWidth = 8;
let rectHeight = 100;
let patternValue = 100000;
let yLoc;
function setup() {
createCanvas(640, 640);
yLoc = height * 0.5;
// for loop example
for (let i = 0; i < 10; i++) {
print(i);
}
// while loop example
let num = 40;
while (num < 50) {
print(num);
num++;
}
rectMode(CENTER);
}
function draw() {
// choose a new number to enter into randomSeed every 60 frames
if (frameCount % 60 == 0) {
patternValue = random(1000000);
}
// choose a new pattern of random numbers by changing the seed value
randomSeed(patternValue);
// random colors
background(random(0, 255), random(0, 255), random(0, 255));
// loop through and draw rectangles on screen
// offset the start of the draw by half the width of the rect
// since we're drawing with rectmode center
for (let i = rectWidth / 2; i < width; i += rectWidth) {
rect(i, yLoc + random(-20, 20), rectWidth, rectHeight);
}
}
// choose a new seed when the mouse is pressed
function mousePressed() {
patternValue = random(1000000);
}
// choose specific randomseed values based on key press
function keyPressed() {
if (key == "a") {
patternValue = 1000;
}
if (key == "b") {
patternValue = 10000;
}
}