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 & HelpSyntax Questions › moving ellipses using array of coordinates
Page Index Toggle Pages: 1
moving ellipses using array of coordinates (Read 3490 times)
moving ellipses using array of coordinates
Jun 15th, 2010, 8:14am
 
I have this:

Code:
float size =.7;
float x=10;
float y=30;
float velx;
float vely;
float targetX=500;
float targetY=200;
float easing = 0.004;
float xx = x;
float yy = y;


void setup(){
background (0, 0, 0);
size(800,800);
ellipseMode(CENTER);
colorMode(HSB,255,255,255,255);
noStroke();
smooth();
noiseDetail(14);
frameRate (10);
}

void draw(){
fill(0,0,0,2);
rect(-5,-5,width+5,height+5);

float vx = (targetX - xx) * easing;
float vy = (targetY - yy) * easing;

xx += vx;
yy += vy;


if(dist(xx,yy,targetX,targetY) < 1) {
targetX = x;
targetY = y;
}

for(int i=1; i<100; i++){
fill(255,0,250,122/i);
ellipse(xx,yy,size/6*i,size/6*i);
}
}


Now I would to use an array for the x and y and an array for targetX and targetY, something to simulate the Aaron Koblin flight patterns, using two list, one for the  starting coordinates and the others with the target coordinates.

Thank you
Re: moving ellipses using array of coordinates
Reply #1 - Jun 15th, 2010, 8:35am
 
Yes, so where are you stuck Have you read Array PVector tutorial might be of interest too.
Re: moving ellipses using array of coordinates
Reply #2 - Jun 16th, 2010, 4:24am
 
ok, thanks, now I've this:

Code:
float size =.7;
float x=10;
float y=30;
float[] targetX = new float [3];
float[] targetY = new float [3];
float[] easing = new float [3];


PVector[] location = new PVector[3];


PVector velocity;


void setup(){
background (0, 0, 0);
size(800,800);
ellipseMode(CENTER);
colorMode(HSB,255,255,255,255);
noStroke();
smooth();
noiseDetail(14);
frameRate (10);
location [0] = new PVector (0, 0);
location [1] = new PVector (100, 87);
location [2] = new PVector (10, 70);
targetX[0] = 500;
targetY[0] = 200;
targetX[1] = 100;
targetY[1] = 800;
targetX[2] = 200;
targetY[2] = 400;
easing[0] = 0.007;
easing[1] = 0.002;
easing[2] = 0.003;

}

void draw(){
fill(0,0,0,5);
rect(-5,-5,width+5,height+5);

for (int f=0; f<3; f++){

velocity = new PVector ((targetX[f] - location[f].x) * easing[f], (targetY[f] - location[f].y) * easing[f]);

location[f].add(velocity);

for(int i=1; i<100; i++){
fill(255,0,250,122/i);
ellipse(location[f].x,location[f].y,size/8*i,size/8*i);
}
}
}


it works perfectly, but I have some other question:

-can I load the PVector array from a txt file?
-can I start the draw of an allipse at a certain time?
Re: moving ellipses using array of coordinates
Reply #3 - Jun 16th, 2010, 6:33am
 
For the record, you can simplify a bit your declarations:
Code:
float size =.7;
float x=10;
float y=30;
float[] targetX = new float[] { 500, 100, 200 };
float[] targetY = new float [] { 200, 800, 400 };
float[] easing = new float [] { 0.007, 0.002, 0.003 };

PVector[] location = new PVector[]
{
 new PVector (0, 0),
 new PVector (100, 87),
 new PVector (10, 70)
};

PVector velocity;


void setup(){
 background(0, 0, 0);
 size(800,800);
 ellipseMode(CENTER);
 colorMode(HSB,255,255,255,255);
 noStroke();
 smooth();
 noiseDetail(14);
 frameRate(10);
}

Quote:
-can I load the PVector array from a txt file
-can I start the draw of an allipse at a certain time

Yes and yes.

OK, to prevent more questions, here are hints:
- use loadStrings() and split() (lot of examples on the forum)
- use millis() with a reference time (computing time spent between two events/actions). Again, lot of examples on the forum.
Re: moving ellipses using array of coordinates
Reply #4 - Jun 18th, 2010, 5:46am
 
Ok, I've done this, I have parsed a Table with the Ben Fry's Table class exemple and I use those values to draw the ellipse at a certain coordinate:

Code:
Table locationTable;
float size =.7;
float x;
float y;
float targetX;
float targetY;
float easing;
int rowCount;
int start;

PVector[] location = new PVector[110];


PVector[] velocity = new PVector [110];


void setup(){
 background (0, 0, 0);
 size(450,551);
 ellipseMode(CENTER);
 colorMode(HSB,255,255,255,255);
 noStroke();
 smooth();
 noiseDetail(14);

 targetX = 500;
 targetY = 200;
 easing = 0.007;
 frameRate (10);
 start = millis();

 locationTable = new Table("locations.tsv");
 rowCount = locationTable.getRowCount();

}

void draw(){
 fill(0,0,0,5);
 rect(-5,-5,width+5,height+5);


 for (int row = 0; row < 55; row++) {
   x = locationTable.getFloat(row, 1);
   y = locationTable.getFloat(row, 2);
 
   location[row] = new PVector (x, y);
   velocity[row] = new PVector ((targetX - location[row].x) * easing, (targetY - location[row].y) * easing);
   location[row].add(velocity[row]);

   for(int i=0; i<110; i++){
fill(255,0,250,122/(i+1));
ellipse(location[row].x,location[row].y,size/8*i,size/8*i);
   }
 }

 if((millis()-start) >= 4000){
   for (int row = 55; row < 110; row++) {
x = locationTable.getFloat(row, 1);
y = locationTable.getFloat(row, 2);

location[row] = new PVector (x, y);
velocity[row] = new PVector ((targetX - location[row].x) * easing, (targetY - location[row].y) * easing);
location[row].add(velocity[row]);

for(int i=0; i<110; i++){
 fill(255,0,250,122/(i+1));
 ellipse(location[row].x,location[row].y,size/8*i,size/8*i);
}
   }
 }
}


but now I can't see the ellipse in movement, where is my mistake?

here's my project file: http://ytrid.altervista.org/stuff/trail2.zip
Re: moving ellipses using array of coordinates
Reply #5 - Jun 18th, 2010, 10:04am
 
I have corrected my sketch in this way:  
Code:
PImage mapImage;
Table locationTable;
Table destinationTable;
float size =.7;
float x;
float y;
float targetX;
float targetY;
float easing;
int rowCount;
int start;

PVector[] location = new PVector[110];
PVector[] destination = new PVector[110];
PVector[] velocity = new PVector [110];


void setup(){
background (0, 0, 0);
size(450,551);
ellipseMode(CENTER);
colorMode(RGB,255,255,255,255);
noStroke();
smooth();
noiseDetail(14);

mapImage = loadImage("pianta-italia-regione.png");

easing = 0.008;
frameRate (10);
start = millis();

locationTable = new Table("locations.tsv");
destinationTable = new Table("destinations.tsv");
rowCount = locationTable.getRowCount();

for (int row = 0; row < 110; row++) {

x = locationTable.getFloat(row, 1);
y = locationTable.getFloat(row, 2);

targetX = destinationTable.getFloat(row, 1);
targetY = destinationTable.getFloat(row, 2);
location[row] = new PVector (x, y);


}

}

void draw(){

tint(100,100,100, 6);
image(mapImage, 0, 0);

//fill(0,0,0,2);
//rect(-5,-5,width+5,height+5);

for (int row = 0; row < 110; row++) {

destination[row] = new PVector (targetX, targetY);

velocity[row] = new PVector ((destination[row].x - location[row].x)*easing , ((destination[row].x - location[row].y)+30)*easing );
location[row].add(velocity[row]);

for(int i=0; i<50; i++){
fill(255,255,250,122/(i+1));
ellipse(location[row].x,location[row].y,size/8*i,size/8*i);
}
}


if((millis()-start) >= 4000){
for (int row = 0; row < 110; row++) {

destination[row] = new PVector (targetX, targetY);

velocity[row] = new PVector ((destination[row].x - location[row].x)*easing , ((destination[row].x - location[row].y)+30)*easing );
location[row].add(velocity[row]);

for(int i=0; i<50; i++){
fill(255,255,250,122/(i+1));
ellipse(location[row].x,location[row].y,size/8*i,size/8*i);
}
}
}
}


but now I can't delay with millis() the second block of ellipse, why?
Page Index Toggle Pages: 1