As a programming exercise, I'm attempting to use a key (in this case, a and b) to turn an animation on and off. What I want the program to do is not draw the rectangle when I press a until I press a again, and similarly for b and the ellipse. I got this to by creating separate on/off switches (a to turn off, A to turn back on, and similarly with b), but I'd really like to only have to use one letter.
Any advice would be appreciated, as this seems relatively easy yet I'm new to programming.
Code is below, and thanks for any help you can give!
float r,e;
boolean flagA, flagB;
void setup() {
size(300, 300);
background(255);
noStroke();
smooth();
frameRate(60);
flagA=true;
flagB=true;
}
void draw() {
if (abs(r-e)<20) {
background(255,0,0);
//println("Woah there, y'all gettin' mighty close in x coords.");
This is a little script that moves a red ball around the screen within the confines of the screen, then slows it down and stops it when you aren't moving it.
I have two questions:
1) How can I create another object where I click that isn't then immediately deleted by the background command in the draw command?
2) Why is it that when the object I'm drawing momentarily appears, instead of appearing where I'm clicking, it seems to be appearing with some relation to the ball?
Thanks for any help you can offer me, and I'd be really happy if someone could think of a way to shorten this code.