We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › particle class instances
Page Index Toggle Pages: 1
particle class instances (Read 1310 times)
particle class instances
Aug 15th, 2006, 2:43pm
 
Still struggling..with the Physics Library..
I would like to ask what should be the right way to construct a class containing particles and then create instances of this class with different particles' attributes (e.g. their location)
From the tendril example, I can see that there is lots of Java involved..which I am not able to understand.
Is there any simpler example of doing this?
I know that what I am asking refers to simple and basic knowledge of Object Oriented Design..which I don't have..but I do try to understand
If anyone has some basic instructions of to get out of this mess.. let me know
Re: particle class instances
Reply #1 - Aug 15th, 2006, 9:55pm
 
You could try something like this (it is Object Oriented)

Code:

ParticleSystem physics = new ParticleSystem(0,0);

class MyClass {
Particle[] particles;

MyClass(int numParticles) {
particles = new int[numParticles];
for (int i = 0; i < numParticles; i++) {
particles[i] = physics.makeParticle();
}
}
}


Basically what that code does is create a class called MyClass which has an array of particles within it. When you create a new instance of MyClass you pass it one parameter which is the number of particles like so:

Code:

MyClass example = new MyClass(5);


Now in order to set each of the particles to a different position you refer to the aforementioned array:

Code:

example.particles[4].moveTo(1,2,3);
example.particles[8].moveTo(12,23,34);


I hope that all makes sense.

 Xavier
Re: particle class instances
Reply #2 - Aug 16th, 2006, 2:00am
 
Thank you so much!!!
It does make more sense now...
Page Index Toggle Pages: 1