We are about to switch to a new forum software. Until then we have removed the registration on this forum.
For my class we need to use 2 for loops one in the setup and one draw, and use one array. Our goal is to create an explosion where you click your mouse. I was able to create the Explosion but I'm confused on how I can get the explosion to be where the mouse is clicked. Here's my code
that's all the code except for 2 curly brackets at the end.
Answers
Can you format your code using the code button?
I just edited it
What you have posted now is EVEN LESS helpful. We can't copy the code out of an image!
FFS
sorry I'm still new to this site, how do I format the code on here?
Right, now that we have your code, we can start working on it. You have several arrays of variables, where the i'th variable in one of those arrays belongs to the i'th ellipse. While this works just fine, it's not good OOP. Instead of doing it this way, let's teach you some actual programming and move ahead to using Object Orientated Programming, with real objects.
Well, you can either read the sticky about how to format code... http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text#latest
Or, the short version: Highlight code, press Ctrl+o.
My class is actually going to be learning OOP this week after our lab is due.
Then you'll have to make the transition from arrays of variables to objects, but in reverse. You'll need an array for each variable in the class...
So you mean I need to set a for loop for each axis?
You should only need one for loop each in draw(), mousePressed(), and setup().
You'll probably need five arrays. Let's say they're called x, y, dx, dy, and c.
In setup(), your for loop - lets say it loops using the variable i - should setup the values for each of the arrays of variables you'll have. That is, it'll set the values for x[i], y[i], dx[i], dy[i], and c[i] for each value of i.
The draw() function's loop will update the values in x[i] and y[i] (for each value of i) based on the values of dx[i] and dy[i]. Then it will use the i'th variables from all of the arrays to render the dot.
The loop in mousePressed() should set all the values for all the dots to some new values... values that will cause each dot's position to be set to where the mouse was clicked, and give it a new, random color (the c array) and velocity (which is what dx and dy arrays are).
Try this yourself now, and post the code of your attempt for more help, if you need it.
So I'm very close I think, the only problem is the dots are present when the program begins.