thanks a lot - now i understand (a little bit more... *g*)
i tried to adapt this one next - it doesn't work...
changed loop() to draw() but nothing happens...
do you have an idea for this one??
i know, i'm an annoying newbie...
but its my first time with processing and i'm not very familiar with programming.
i'm trying to learn - learning by doing...
i can retrace the parts of the code, but i do not
find the specific point which is responsible for
the problem in beta 0090...
can anybody please help me?!?!
thx
code:
int NUM_PARTICLES = 10000;
int NUM_ATTRACTORS = 6;
Particle[] particle;
Attractor[] attractor;
float damp = 0.00002;
float accel = 10000;
class Particle {
float x,y,vx,vy;
Particle() {
x = random(width);
y = random(height);
vx = random(-accel/2,accel/2);
vy = random(-accel/2,accel/2);
}
void step() {
for (int i = 0; i < attractor.length; i++) {
float d2 = sq(attractor[i].x-x) + sq(attractor[i].y-y);
if (d2 > 0.1) {
vx += accel * (attractor[i].x-x) / d2;
vy += accel * (attractor[i].y-y) / d2;
}
}
x += vx;
y += vy;
vx *= damp;
vy *= damp;
line(x,y,x,y);
}
}
class Attractor {
float x,y;
Attractor() {
x = random(width);
y = random(height);
}
}
void setup() {
size(800,600);
attractor = new Attractor[NUM_ATTRACTORS];
particle = new Particle[NUM_PARTICLES];
scatter();
}
void loop() {
for (int j = 0; j < particle.length; j++) {
particle[j].step();
}
}
void scatter() {
background(255);
stroke(0,0,0,8);
for (int i = 0; i < attractor.length; i++) {
attractor[i] = new Attractor();
}
for (int i = 0; i < particle.length; i++) {
particle[i] = new Particle();
}
}
void mousePressed() {
scatter();
}