I have the following code, I have to create 2 new variables “pulseWidth” and “grow” and create if-statements to ask the balls drawn to grow and shrink in a pulsing manner. I am not sure as to how to write the if-statements.
var x1 = 400;
var x2 = 300;
var x3 = 200;
var move1 = 5 ;
var move2 = 5 ;
var move3 = 5 ;
function setup() {
createCanvas(800, 800);
background(150,150,150);
}
function draw() {
// background(150);
fill(225, 0, 0);
ellipse(x1, x1, x1, x1);
x1 = x1 + move1;
fill(0, 225, 0);
ellipse(x2, 500, 30, x2);
x2 = x2 + move2;
fill(0, 0, 225);
ellipse(x3, 400, x3, 300);
x3 = x3 + move3;
if ((x1 > width) || (x1<=0))
{
move1 = move1 * -1;
}
if ((x2 > width) || (x2<=0))
{
move2 = move2 * -1;
}
if ((x3 > width) || (x3<=0))
{
move3 = move3 * -1;
}
}
the psuedocode I believe is in the right direction is
if pulseWidth > 50 or pulseWidth < 10
Multiply grow by -1 to reverse it
any help will be appreciated!