We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've been trying to do something with this project I have but failed always so far :) so decided to ask here :)
I want the particles to go around the ellipse from Rock class, not through it but around it, like a rock inside a river that water flows around it. Any suggestions ?
int NUM_PARTICLES = 1000;
ParticleSystem p;
Rock r;
void setup()
{
smooth();
fullScreen(P2D);
//size(700,700,P2D);
//background(0);
p = new ParticleSystem();
r = new Rock();
}
void draw()
{
background(0);
p.update();
p.render();
r.rock();
}
float speed = 1;
class Particle
{
PVector position, velocity;
Particle()
{
position = new PVector(random(width),random(height));
velocity = new PVector();
}
void update()
{
velocity.x = speed*(noise(position.y));
velocity.y = speed*(noise(position.x));
position.add(velocity);
if(position.x<0)position.x+=width;
if(position.x>width)position.x-=width;
if(position.y<0)position.y+=height;
if(position.y>height)position.y-=height;
}
void render()
{
stroke(0, 0, 255, 80);
line(position.x,position.y,position.x-velocity.x,position.y-velocity.y);
}
}
class ParticleSystem
{
Particle[] particles;
ParticleSystem()
{
particles = new Particle[NUM_PARTICLES];
for(int i = 0; i < NUM_PARTICLES; i++)
{
particles[i]= new Particle();
}
}
void update()
{
for(int i = 0; i < NUM_PARTICLES; i++)
{
particles[i].update();
}
}
void render()
{
for(int i = 0; i < NUM_PARTICLES; i++)
{
particles[i].render();
}
}
}
class Rock{
void rock()
{
noFill();
stroke(255);
strokeWeight(4);
ellipse(mouseX,mouseY,50,50);
}
}
Answers
I worked on a bit more and now I have almost what I want, I want it to be smoother I can see the lines of Force variable. And the flow is not visually so good.
here is the new code
One idea, did you look at repel functions in shiffmans book nature of code
There is a chapter on particles
2nd idea - make a 2nd bigger circle (or row of them) to make it fluent. Those are invisble but influence the particles