beginner: animate PVector points continuously
in
Programming Questions
•
2 years ago
hey, sorry this is really basic. i am new to processing..(from actionscript and QC)
i have this nice exampe file from http://vormplus.be/blog/article/processing-month-day-2-connecting-points-part-2
and i want to change it so that the points animate constantly and smoothly between new random positions.
but i dont understand the best way to achieve this animation with points in Processing.
using basic if/else structure i have mocked up the most primitve version of what i want (but only runs once motion once, the reset point isnt working?).. would love advice on the correct animation method and how to get more sophisticated maths for the movement. thanks! :)
i have this nice exampe file from http://vormplus.be/blog/article/processing-month-day-2-connecting-points-part-2
and i want to change it so that the points animate constantly and smoothly between new random positions.
but i dont understand the best way to achieve this animation with points in Processing.
using basic if/else structure i have mocked up the most primitve version of what i want (but only runs once motion once, the reset point isnt working?).. would love advice on the correct animation method and how to get more sophisticated maths for the movement. thanks! :)
- int numPoints = 12;
PVector[] points = new PVector[numPoints];
PVector[] newPoints = new PVector[numPoints];
void setup()
{
size( 450, 400 );
for (int i = 0; i < numPoints; i++) {
points[i] = new PVector( random(width), random(height) );
newPoints[i] = new PVector( random(width), random(height) );
}
//noLoop();
}
void draw()
{
smooth();
background(0);
noFill();
for (int i = 0; i < numPoints; i++) {
for (int j = 0; j < numPoints; j++) {
strokeWeight(1);
if ( j != i ) {
float dst = dist( points[i].x, points[i].y, points[j].x, points[j].y );
// if ( dst < 255 ) {
stroke( 255, 255 - 0);
line( points[i].x, points[i].y, points[j].x, points[j].y );
// }
}
}
stroke( 255 );
strokeWeight(4);
point( points[i].x, points[i].y );
}
// ANIMATE
for (int i = 0; i < numPoints; i++) {
// move X
if( points[i].x < newPoints[i].x){
points[i].x++;
}else if( points[i].x > newPoints[i].x){
points[i].x--;
}else if(points[i].x == newPoints[i].x){
newPoints[i].x = random(width);
}
// move Y
if( points[i].y < newPoints[i].y){
points[i].y++;
}else if( points[i].y > newPoints[i].y){
points[i].y--;
}else if(points[i].y == newPoints[i].y){
newPoints[i].y = random(height);
}
point( points[i].x, points[i].y );
}
// saveFrame("images/random-connections-"+numPoints+".png");
}
1