We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So for a visualization of data I want a specific number of particles to move in a constrained area and then when the space bar is pressed move to another specific area and have the particles move in a different constrained space.
How would you do this and also change the number of particles in these constrained areas (go from 60 to 50).
Answers
Start with nothing.
Now add a Particle.
Pretend you are the particle. What do you need to know about yourself? Maybe your position? Color?
How do you know where you start?
How do you look? How do you move?
Do you exist?
Do you have a chance at being?
There you are. Why don't you dance? Do you have friends?
Are your friends real?
Do they have a chance at being?
Do they dance with you?
Great answer @TfGuy44 :)
How far did you get with it, @RifleGirl ? Do you have particles yet? Let's see the code you have now, and we can work on constraining them to areas.
@TfGuy44 This is kind of what I've got going right now... (not too much done......)
Close. You have global variables px and py that you don't use - each Particle will have it's own copy of the px and py variables defined inside the class. The move() function you have is fine, but needs to be inside the Particle class too, since it's how a single Particle knows how to move. You're also missing a draw() method for your Particle class.
Here, I've tidied things up a bit, and added a second particle so that you can see how the same class definition - class particle - can be used to make more than one object.
The next step is to have an ARRAY of Particles, and create, move, and draw them using some for loops. And here's a hint: the Particle class doesn't need to change at all to do this! Try your hand at it, using the handy guide that @GoToLoop will now magically appear and post...
My guide? How about @PhiLho's?:
http://forum.processing.org/two/discussion/8081/from-several-arrays-to-classes
Especially the "Using the class" section! *-:)
@TfGuy44 Wow yeah that's definitely better... So now I am creating an array, is there a better way of going about the void draw() so that I don't have 50 p.draw and p.move?
Yes! Use a for loop!
If we got an array or any Iterable:
http://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html
we're illegible to choose what's known as the for-each (or enhanced) loop:
In order to traverse/iterate over it! :-bd
Let's say you've got a Particle[] array or an ArrayList<Particle>, which is an Iterable by the way,
Particle[] particles = new Particle[100];
orArrayList<Particle> particles = new ArrayList();
In either case you can use:
for (Particle p : particles) p.script();
*-:)@GoToLoop those are really helpful. I am trying to use some of the functions on the ArrayList html. I am basically trying to get the number of particles there should be from an existing array (there are 4 different numbers in each array so that the amount changes based on the mouse being clicked). The issue is there are 4 different arrays and the particles are supposed to be set up in 4 different areas. (I'm basically combining two of my "discussions" into one project haha)
final Particle[] particles = new Particle[100];
@GoToLoop Haha sorry if I'm not clear. My particles are to show population growth and decline in 4 years in 4 different areas. So when you click the mouse the particles increase or decrease!
and then I have the number of particles I need in specific areas here
My Particles class is here
It is sounding though that I will need to make 4 different particle classes.
http://forum.processing.org/two/discussion/8081/from-several-arrays-to-classes
@GoToLoop So then to call the given number in an array and make that the number of particles that appear do you have to define that in the Particle class?
I believe you wish for a particular Area to control some amount of Particle objects, right?
Then you need to include 1 array of Particle[] as an Area property as well:
@GoToLoop I see what you're doing but can't seem to implement it. My main issue right now is that I cannot seem to call to the one array of numbers I have. I am trying to focus less on the areas now and just on one array of particles (just so I understand how to do that first, then I will try to tackle that problem).
I uploaded my new code, maybe you can see my problem? (also @TfGuy44) I figure there must be something I'm not seeing...
Sorry, I'm not listening. I was totally sidetracked and wrote this instead.