Good day, I’ve been given an assignment to code a program that requires me to create 4 Leds that change to 2 different colors depending on which mouse button is pressed. If the right mouse button is pressed, the gauge bar is suppose to fill up per mouse press until 100%; this percentage must be shown below the gauge bar. If the left mouse button is pressed, the gauge bar is suppose to lower per mouse press until 0%.
I know im supposed to use two ‘rectangles’ with one being fractionally smaller than the other; the smaller one is meant to act as the animated “fill up” procedure but i seem to be struggling with the code for this. Please assist if possible
There’s no hardware element, yet; for the time being it’s just coding.
By LEDs, I meant ellipse’s. Thus far I’ve been able to create the 4 ellipses as well as the gauge bar(rectangle). I’m yet to code the ellipses to change color per mouse press as well as the code for the rectangle to ‘fill up/down’ after each mouse press.
I’m currently attempting to code the rectangle using @Chrisir 's advice.
Use a variable to track the value and one to adjust it (i.e. called increment).
Add increment to the value in draw();
Update the increment value in mousePressed();
int value, increment;
...
void mousePressed() {
if (mouseButton == LEFT) {
increment = 1;
} else if (mouseButton == RIGHT) {
increment = -1;
}
}