How to create a ball that remains in a status of uniform motion in a curve line?
              in 
             Programming Questions 
              •  
              7 months ago    
            
 
           
             Hi everyone, 
            
             
            
            
             
            
            
             
            
             
            
             
            
            
 
            
           
             I use loadStrings() method to load all the discrete X,Y coordinates from a txt file. Then I put them in a string array. If I directly put ellipse(X,Y,10,10) under the draw() method, the ball will not move in a constant speed, because the distance between each sets of coordinates is different. As the ball moves in a high density area, it slows down dramatically; as it moves in a discrete area, it moves fast. Is there any way to make it move in a constant speed in the whole route? or should I use some other shape like to create a curve first before draw()?
            
            
             Here is my scripts:
            
            - String[] lines;
 - int index=0;
 - void setup(){
 - lines=loadStrings("positions.txt");
 - frameRate(12);
 - noStroke();
 - background(0);
 - }
 - void draw(){
 - fill(0,30);
 - rect(0,0,width,height);
 - fill(255);
 - if(index<lines.length){
 - String[] pieces=split(lines[index],'\t');
 - if(pieces.length==2){
 - int x=int(pieces[0]);
 - int y=int(pieces[1]);
 - ellipse(x,y,8,8);
 - }
 - index++;
 - }
 - }
 
             Here is the position.txt:
            
            - 70 35
 - 69 35
 - 68 39
 - 67 42
 - 66 47
 - 64 51
 - 64 54
 - 63 57
 - 60 60
 - 58 64
 - 51 69
 - 48 72
 - 44 73
 - 39 75
 - 35 75
 - 30 75
 - 25 75
 - 21 75
 - 17 73
 - 13 69
 - 12 66
 - 11 61
 - 11 57
 - 10 49
 - 10 45
 - 10 38
 - 12 32
 - 13 29
 - 16 23
 - 20 19
 - 24 16
 - 27 15
 - 31 13
 - 33 13
 - 37 13
 - 40 15
 - 42 16
 - 45 19
 - 46 21
 - 47 24
 - 48 26
 - 48 29
 - 48 33
 - 47 39
 - 43 45
 - 42 47
 - 38 50
 - 35 51
 - 32 51
 - 30 51
 - 27 50
 - 27 50
 - 26 46
 - 26 41
 - 29 36
 - 30 34
 - 31 33
 - 31 33
 - 32 33
 - 33 33
 - 34 33
 - 34 33
 - 35 33
 - 37 33
 - 39 33
 - 42 32
 - 44 31
 - 46 29
 - 48 29
 - 49 27
 - 52 24
 - 53 23
 - 57 19
 - 61 16
 - 63 14
 - 67 13
 - 69 12
 - 69 12
 - 77 11
 - 77 11
 - 80 11
 - 86 16
 - 90 21
 - 93 25
 - 95 29
 - 95 32
 - 95 33
 - 95 37
 - 94 41
 - 93 44
 - 92 46
 - 91 49
 - 89 51
 - 87 55
 - 85 59
 - 82 62
 - 80 64
 - 79 67
 - 77 69
 - 74 71
 - 68 72
 - 65 73
 - 63 73
 - 62 73
 - 60 72
 - 58 69
 - 57 67
 - 57 66
 - 56 60
 - 56 56
 - 56 54
 - 58 49
 - 60 47
 - 62 47
 - 63 47
 - 67 48
 - 70 52
 - 73 55
 - 74 57
 - 74 58
 - 74 60
 - 74 62
 - 73 65
 - 70 68
 - 67 69
 - 65 70
 - 63 70
 - 62 70
 - 60 68
 - 57 65
 - 55 64
 - 50 62
 - 46 61
 - 40 60
 - 38 60
 - 36 60
 - 32 61
 - 30 62
 - 27 64
 - 26 68
 - 25 71
 - 25 77
 - 25 81
 - 26 84
 - 28 86
 - 31 87
 - 33 88
 - 36 88
 - 39 86
 - 41 85
 - 43 83
 - 44 81
 - 45 76
 - 45 74
 - 45 71
 - 40 67
 - 37 65
 - 34 63
 - 33 61
 - 33 61
 - 32 60
 - 33 49
 - 37 45
 - 41 41
 - 45 39
 - 47 38
 - 51 37
 - 54 37
 - 58 38
 - 61 41
 - 63 44
 - 65 46
 - 66 49
 - 66 51
 - 67 55
 - 67 58
 - 67 60
 - 66 62
 - 64 65
 - 63 66
 - 61 67
 - 60 68
 - 58 68
 - 55 69
 - 54 69
 - 51 69
 - 48 69
 - 46 68
 - 45 66
 - 44 65
 - 44 63
 - 44 61
 - 44 59
 - 44 56
 - 44 55
 - 45 53
 - 47 52
 - 49 50
 - 50 48
 - 51 47
 - 52 46
 - 54 46
 - 55 45
 - 55 45
 - 56 44
 - 57 44
 
             Thanks,
            
            
             Zhenyang
            
 
            
              
              1  
            
 
            