I have a program where some dots move around the screen randomly. When they go off the screen, they just come back on at the opposite edge travelling at the same speed in the same direction. At the moment, they are constrained to the screen, but I want to restrict them to within a circle, rather than a rectangle/square area. Any ideas how to do this?
I have a feeling there might be a mathsy way to restrict it, but not sure. A seemingly easier alternative would be to just fill in a shape which filled in the corners, but I don't know how to draw a filled triangle with one of the sides caved in!
Some background: I'm using a switch/case statement as menu screens in my program. I have buttons to navigate through, and I've made these using the cp5 button controller. On screen 4, I have 2 buttons, which work perfectly the first time you see them. When I loop my program back around (through screens 1-3), when I get to screen 4 again the buttons do not work on the first click! They always work on the second click though. I have no idea what could be causing this bug... Is there some way to reset the buttons or something? I'll paste bits of program if needed but not sure which bits might be relevant.
Any help would be great! This sounds like a small issue but I will be timing the user response, so it's important the button always works first click.
I'm a noob, so please make answers as simple as possible. I want to create a program where there are balls moving randomly (done this bit). I've made the balls as a separate class, so I have to make a new variable every time I want to make a ball. This is fine for a couple of objects, but I want 20 balls (and at some point I will also want to vary this number).
I thought perhaps I could make a for loop that creates the variables? Something like...
for (i=1; i<21; i++) {
Ball ball[i];
}
void setup () {
for (i=1; i<21; i++) {
ball[i] = new Ball();
}
So this would make 20 balls, calling each one ball1, ball2, ball3 etc. How can I do this? If I cannot use a for loop, what other way would be good for making many variables like this?