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 › move particles to specific region in the image
Page Index Toggle Pages: 1
move particles to specific region in the image (Read 593 times)
move particles to specific region in the image
Nov 17th, 2008, 9:28pm
 
...

in the first step i have flocking particles around the screen, in the second step i want those particles to move to the place, where i have dark image region  (silhouette), and to fill it equally in that region.
Any suggestions how to start coding such a movement?
Re: move particles to specific region in the image
Reply #1 - Nov 18th, 2008, 1:06am
 
I love questions like this! B/c there are so many (potentially good) answers. Can't wait to hear what others say.

Is the silhouette moving? If yes, it becomes more complex.

Here's how I'd do it w/ a static, non-moving silhouette:

I'd reverse-engineer it: First, pick a bunch of random points inside the silhouette. Assign one to each particle.

So the particles float around as normal.

When it's go-time, the destination points -- inside the silhouette -- becomes attractors, and you factor them into the particles' motion.

The strength & characteristics of the attraction will determine how the migration looks; personally I'd do something fairly weak, but consistent (i.e. doesn't decrease as the square of distance) so the particles sort of slowly spiral into place.

But the important thing is that each particle has its own unique destination point, which is a pre-calculated point inside the silhouette. And for the first part of the animation, that destination point doesn't influence anything -- but when you flip a switch, it attracts the particle to it.

Does that make sense?
Re: move particles to specific region in the image
Reply #2 - Nov 18th, 2008, 7:38pm
 
thank you for your answer!
it's probably the way to do it. I'll post some code after i do some research  (btw similar topic here) and  use for the silhouette thing.
Re: move particles to specific region in the image
Reply #3 - Nov 18th, 2008, 9:20pm
 
For the record, there is another a similar request: Particle typeface.
Re: move particles to specific region in the image
Reply #4 - Nov 19th, 2008, 3:30pm
 
...

so far i managed to follow the line, but have no idea (yet)  how to distribute points in the area. Any ideas?

Code:

// press any key to reset, drag-release mouse to distribute points

void setup() {
size(400,300);
reset();
}

int num=69;
Ball[] b=new Ball[num];
boolean moving=false; // if balls are moving to the line
int d=0; // current recorded mouse point
int[] recx=new int[num];
int[] recy=new int[num];
int dSS;

void draw(){
background(10,20,30);
for (int i=0;i<num;i++){

if (!moving){
b[i].move();
}
else {
//repeat();
stroke(255,255,0);
if (i>0){
line(recx[i],recy[i],recx[i-1],recy[i-1]);
}
b[i].x+=(recx[i]-b[i].x)*.05;
b[i].y+=(recy[i]-b[i].y)*.05;
}
b[i].show();
}
}

void mouseDragged(){
moving=false;
if (d==0){
for (int i=0;i<num;i++){
recx[i]=mouseX; // reset previous draw;
recy[i]=mouseY;
}
}
if (mousePressed==true){
for (int i=1;i<d;i++){
stroke(255);
line(recx[i],recy[i],recx[i-1],recy[i-1]);
}
}
if (d<num){
recx[d]=mouseX;
recy[d]=mouseY;
d++;
}
}

void mouseReleased(){
if (d<num){ //i use it when mouse records number (recx, recy) is smaller than particle number (num)
dSS=-1;
for (int i=d;i<num;i++){
if (d>0){
dSS+=2;
//println(i+"="+dSS);
if(i>dSS){
recx[i]=recx[i-dSS]; //so empty mouse records are filled with previous mouse records
recy[i]=recy[i-dSS]; // not elegant.... i know... any better ideas?
}
}
}

}
moving=true;
d=0;
}

void reset(){
for (int i=0;i<num;i++){
b[i]=new Ball(random(-2,2),width/2,random(height));
}
}

void keyReleased(){
reset();
moving=false;
}

class Ball{
float speed;
float x;
float y;
Ball (float _speed, float _x, float _y) {
speed=_speed;
x=_x;
y=_y;
}

void move(){
x+=speed;
borders();
}

void show(){
noFill();
stroke(255,0,0);
ellipse(x,y,5,5);
}

void borders(){
if (x<0){
x=width;
}
if (x>width){
x=0;
}
}
}
Re: move particles to specific region in the image
Reply #5 - Nov 19th, 2008, 3:38pm
 
here is good example how i would like it to work (follow the behaviour of orange particles, ie how they move to a silhouette through a hand):
http://www.vimeo.com/1031151
Page Index Toggle Pages: 1