Move along a PVector []
              in 
             Programming Questions 
              •  
              6 months ago    
            
 
           
             hi, 
            
a small question .
how do i make a ball move along the lines that connect the dots?
            
            
            
            
             
if i do
             
             
             
but how do i do it for the all the points in the array?
             
thanks
             
           
 
            
           a small question .
how do i make a ball move along the lines that connect the dots?
- public class Ball {
- private PVector location=new PVector();
- private PVector [] points;
- int step;
- int increment;
- public Ball(PVector[] points) {
- this.points = points;
- location=points[0].get();
- step=0;
- increment=1;
- }
- public void setLocation(PVector loc) {
- location=loc;
- }
- public PVector getLocation() {
- return this.location;
- }
- public void move () {
- location.x = lerp(location.x, this.points[step].x, .11f);
- location.y = lerp(location.y, this.points[step].y, .11f);
- if (step <= 0) {
- increment=abs(increment);
- }
- else if (step >= this.points.length-1) {
- increment = -abs(increment);
- }
-   
- location.set(points[step].x, points[step].y, 0);
- pushStyle();
- fill(0);
- noStroke();
- ellipse(location.x, location.y, 10, 10);
- popStyle();
- step+=increment;
- }
- }
- private PVector [] points;
- Ball ball;
- public void setup() {
- size(800, 700);
- textSize(12);
- points=new PVector[10];
- randomSeed(233);
- for (int i=0; i<points.length; i++)
- points[i]=new PVector((int)random(0, width), (int)random(0, height));
- ball=new Ball( points);
- }
- public void draw() {
- background(255);
- smooth();
- frameRate(3);
- // pushStyle();
- noStroke();
- fill(255, 0, 0);
- for (int i=0; i<points.length; i++) {
- ellipse(points[i].x, points[i].y, 20, 20);
- }
- // popStyle();
- stroke(1);
- for (int i=1; i<points.length; i++) {
- line(points[i-1].x, points[i-1].y, points[i].x, points[i].y);
- }
- ball.move();
- }
if i do
- public void move () {
- location.x = lerp(location.x, this.points[1].x, .11f);
- location.y = lerp(location.y, this.points[1].y, .11f);
- pushStyle();
- fill(0);
- noStroke();
- ellipse(location.x, location.y, 10, 10);
- popStyle();
- }
- }
but how do i do it for the all the points in the array?
thanks
 
              
              1  
            
 
            
 
 
           
 
             
 
            