xxxxxxxxxx
68
let rectWidth= 8;
let rectHeight = 100;
let patternValue=100000;
let yLoc0, yLoc1
function setup() {
createCanvas(640, 640);
yLoc0=height*.25;
yLoc1=height*.75
//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() {
// if (frameCount%10==0){
// patternValue= random(1000000);
// }
randomSeed(patternValue); //it is telling p5 which random pattern to choose
// background(random(0,255), random(0,255), random(0,255));
// //loop through and draw reactangles on screen, offset the start of the draw by half the width of the rect, since we are drawing with rectmode center
// for (let i=rectWidth/2; i<width; i= i+rectWidth){
// rect(i, yLoc0+random(-30,30), rectWidth, rectHeight);
// }
background(100);
for (let i=rectWidth/2; i<width; i= i+rectWidth){
let noiseValue = (noise(frameCount*0.01, i*0.01) - 0.5)*100;
let scaleNoise=(noiseValue-0.5)*100;
rect(i, yLoc0+noiseValue, rectWidth, rectHeight);
}
for (let i=rectWidth/2; i<width; i= i+rectWidth){
let noiseValue = (noise(frameCount*0.01, i*0.001));
let angle=(noiseValue)*TWO_PI;
push();
translate(i, yLoc1);
rotate(angle);
rect(0,0, rectWidth, rectHeight);
pop();
}
}
function mousePressed(){
patternValue= random(1000000);
}
function keyPressed(){
if (key=='a'){
patternValue= random(1000000);
}
}