J'ai essayé de faire quelque chose avec ce projet, je n'ai toujours échoué jusqu'à présent :) donc décidé de demander ici :)Traitement des particules
Je veux que les particules vont autour de l'ellipse de la classe Rock, non à travers elle mais autour de lui, comme une roche à l'intérieur d'une rivière que l'eau coule autour d'elle. Aucune suggestion ?
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);
}
}
EDIT: 1
Je l'ai fait un peu de travail de mon propre sur hier et je suis proche de ce que je veux, a encore un peu issues.I visuelle veulent se débarrasser des bords du flux et quand je bouge la souris je peux encore voir les lignes de l'ellipse de la force. Voici le résultat.
int NUM_PARTICLES = 9000;
ParticleSystem p;
Rock r;
void setup()
{
smooth();
size(700,700,P2D);
p = new ParticleSystem();
r = new Rock();
}
void draw()
{
background(0);
p.update();
p.render();
r.rock();
}
float speed = 2;
float rad = 100;
class Particle
{
PVector position, velocity;
float initialPosY;
Particle()
{
position = new PVector(random(width), random(height));
initialPosY = position.y;
velocity = new PVector();
}
void update()
{
velocity.x = speed;
velocity.y = 0;
float d = dist (position.x, position.y, mouseX, mouseY);
if (d < rad) {
float force = map(d, 0, rad, speed, 0);
if (position.x < mouseX) {
if (position.y < mouseY) {
velocity.y = -force;
} else {
velocity.y = force;
}
} else {
if (position.y < mouseY) {
velocity.y = force;
} else {
velocity.y = -force;
}
}
position.add(velocity);
} else {
position = new PVector(position.x+speed, initialPosY);
}
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(255, 255, 255, 80);
point(position.x, position.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);
}
}
Vous devriez ajouter cela comme une modification à votre question, et non une réponse, car il ne s'agit pas d'une réponse –