Need help with buttons
in
Programming Questions
•
1 year ago
I am trying to make the red button stop the ball from moving, the green button starts movement again.
blue button when on turns dark blue and ball starts growing, light blue when OFF
blue button when on turns dark blue and ball starts growing, light blue when OFF
Yellow button ON turn dark yellow and starts shrinking the ball
when off turns light yellow to start shrinking the ball.
Any help, tips or advice would be tremendously appreciated. I am reading the book and cant seem to figure this out.
My code so far is this...
when off turns light yellow to start shrinking the ball.
Any help, tips or advice would be tremendously appreciated. I am reading the book and cant seem to figure this out.
My code so far is this...
int x = 50;
int speed = 1;
void setup() {
size(400,400);
}
void draw() {
background(255);
//set sllipse and rect to center
rectMode(CENTER);
ellipseMode(CENTER);
{//draw large rectangle
fill(255);
rect(200,120,390,200);
}
{//draw red button
fill(255,0,0);
rect(50,250,50,25);
}
{//draw green button
fill(0,200,0);
rect(150,250,50,25);
}
{//draw blue button
fill(0,0,200);
rect(250,250,50,25);
}
{//draw yellow button
fill(225,225,0);
rect(350,250,50,25);
}
// Add the current speed to the x location.
x = x + speed;
if ((x > width-30) || (x < 30)) {
// If the object reaches either edge, multiply speed by -1 to turn it around.
speed = speed * -1;
}
// Display circle at x location
stroke(0);
fill(175);
ellipse(x,110,50,50);
}
1