How to change colour on impact
in
Programming Questions
•
1 year ago
Hey just having difficulties changing the colour of the triangle now every time it hits an edge, anyone able to help please?
int x = 100;
int y = 0;
int speed = 5;
int state = 0;
void setup() {
size(200, 200);
// frameRate(3);
}
void draw() {
background(255);
stroke(0);
fill(175);
// rect(x, y, 9, 9);
triangle (x, y,
x+9, y,
x+4.5, y+9 );
if (state == 0) {
x = x + speed;
y = y + speed;
if (x > width-10) {
x = width-10;
state = 1;
}
}
else if (state == 1) {
x = x - speed;
y = y + speed;
if (y > height-10) {
y = height-10;
state = 2;
}
}
else if (state == 2) {
x = x - speed;
y = y - speed;
if (x < 0) {
x = 0;
state = 3;
}
}
else if (state == 3) {
x = x + speed;
y = y - speed;
if (y < 0) {
y = 0;
state=0;
}
}
}
1