xxxxxxxxxx
25
//3.3: Else and Else if, AND and OR - p5.js Tutorial
var x = 0; //
var speed = 3; // need to assign variables
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
stroke(180,0,220);
strokeWeight(5);
fill(255,0,255,100);
rect(x, 150, 100,100);
if (x > 300 || x <0) { // conditional stament used here as bouncing rect. you can use width instead of writing the number but here i wanted to make it bounce of screen.
// x = -3 //this was a part of an error but what it does is it goes back to the starting point every time. check it out.
speed = speed * -1;
}
x = x + speed; // you can see your variables being used.
}