Loading...
Logo
Processing Forum
mattklynch's Profile
8 Posts
8 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    I chopped out everything necessary.  I'm trying to solve this in 2d and then move up to 3d with it, so im trying to find a solution that will work for either case.  Essentially I'm trying to create a plane out of connected scattered points, and in order to do so in 3d I have found that the easiest way would be to plot all connection lines, and then run something that wont draw any lines that intersect any other lines, so the result is a triangulated landscape.  So i'm not looking for the intersection  point but how to tell lines are intersecting and boolean them out.

    i really didn't understand what was on the wiki page

    nor could I find any existing examples.  any help would be much appreciated.  thanks!


    **i just realized that it will count the end points as intersections and delete them as well.  anyone have any other suggestions?



    1. Attractor[] attractor = new Attractor[7];


    2. //////////////////////////////////////////////////////////////
    3. void setup() {
    4.   size(800, 800);
    5.   smooth(); 
    6.   for (int i = 0; i < attractor.length; i++) {
    7.     attractor[i] = new Attractor( random(width), random(height) );
    8.   }

    9. }

    10. void draw() {
    11.   //background(0); 
    12.   for (int i=0; i < attractor.length; i++) {
    13.       attractor[i].update();
    14.     }

    15. }

    16. //////////////////////////////////////////////////////////////
    17. class Attractor {
    18.   float x,y;
    19.   
    20.   Attractor(float _x, float _y ) {
    21.     x = _x;
    22.     y = _y;
    23.   }
    24.   
    25.   void update() {
    26.       stroke(255,0,0);
    27.       strokeWeight(.025);
    28.       line(x-4, y, x+4, y);
    29.       line(x, y-4, x, y+4);
    30.       
    31.        for (int i = 0; i < attractor.length; i++) {
    32.          
    33.         
    34.          //if (dist(x, y, attractor[i].x, attractor[i].y) < 100 ) { 
    35.              stroke(#ff0000);
    36.           line(x, y, attractor[i].x, attractor[i].y);

    37.         //}
    38.       }
    39.       
    40.   }

    41. }

    **update: i ended up just drawing it with vertex and then rotating the entire object

    I'm playing with vectors and direction of vectors and I can't seem to draw a line perpendicular to the line created in my drawVector() area.  I dont want a rectangle because I need to draw a shape later in another code, but first i need to get down how to get a line perpendicular to the atan2() line (which i have set at rotating to the -atan2() because i want it perpendicular to the force)

    or better yet, if in the drawVector() it WAS a rectangle, say

       translate(l.x, l.y);
           rotate(-atan2(v.y,v.x) );  
           rect(0, 0, 55, 10);
           popMatrix(); 

    how do you call out the corners of those rectangles? Say I want a line that comes from the top left corner of the rectangle, how do i define that point?


      thanks!

    1. float G = 5;
    2. boolean showVectors = true;
    3. Attractor[] attractor = new Attractor[5];
    4. Ball[] balls = new Ball[1]; 

    5. //////////////////////////////////////////////////////////////
    6. void setup() {
    7.   size(800, 800);
    8.   smooth(); 
    9.   for (int i = 0; i < attractor.length; i++) {
    10.     attractor[i] = new Attractor( random(width), random(height) );
    11.   }
    12.   for (int i=0; i <balls.length; i++) {
    13.     balls[i] = new Ball(random(width), random(height) );
    14.   }
    15. }

    16. void draw() {
    17.   background(128); 
    18.   for (int i=0; i < attractor.length; i++) {
    19.       attractor[i].update();
    20.     }
    21.   for (int i = 0; i < balls.length; i++) {
    22.       balls[i].update();
    23.     }
    24. }

    25. void keyPressed() {
    26.   saveFrame("ballForce01_####.png"); 
    27. }

    28. void mousePressed() {
    29.   setup();
    30. }

    31. //////////////////////////////////////////////////////////////
    32. class Ball {
    33.   PVector l, v, a; 
    34.   
    35.   // ball constructor
    36.   Ball(float _x, float _y) {
    37.     l = new PVector(_x,_y);
    38.     v = new PVector();
    39.   }

    40.   // ball functions
    41.   void update() {
    42.     a = new PVector(); 
    43.     for (int i = 0; i < attractor.length; i++) {
    44.       a.add(attractor[i].getAccel(l.x,l.y));
    45.     }
    46.     
    47.     v.add(a);
    48.     l.add(v); 
    49.     render();
    50.   }

    51.   void render() {
    52.     stroke(0);
    53.     strokeWeight(1);
    54.    
    55.     if (showVectors) {
    56.       drawVector();
    57.     }
    58.   }
    59.   
    60.   void drawVector() {

    61.     
    62.      pushMatrix();
    63.        // transform to the velocity vector
    64.        translate(l.x, l.y);
    65.        rotate(-atan2(v.y,v.x) );  
    66.        line(0,0,25,0);
    67.        popMatrix(); 
    68.          

    69.   }
    70. }


    71. //////////////////////////////////////////////////////////////
    72. class Attractor {
    73.   float x,y;
    74.   
    75.   Attractor(float _x, float _y ) {
    76.     x = _x;
    77.     y = _y;
    78.   }
    79.   void update() {
    80.       stroke(255,0,0);
    81.       strokeWeight(1);
    82.       line(x-4, y, x+4, y);
    83.       line(x, y-4, x, y+4);
    84.   }

    85.   PVector getAccel(float px, float py) {
    86.       PVector a = new PVector(0,0,0); 
    87.       float d2 = sq(dist(px,py,x,y));
    88.       if (d2 > 10) {
    89.         a.x = G * (x-px) / d2;
    90.         a.y = G * (y-py) / d2;
    91.       }
    92.       return a; 
    93.    }
    94. }

    I'm running into a problem with exporting multiple objects in one code with a key stroke activated export.  The issue is if I put the record strings in the drawBall() string it will only give me one object, however it yeilds nothing with placed up where the oop instantiation  is, but the other point and image exporters work still.  does anyone have any advice?
    *note: code is a little sloppy looking because i have been cutting and pasting stuff around to get it to work
    1. import peasy.*;
    2. import processing.dxf.*;

    3. boolean record;

    4. PeasyCam cam;

    5. float [] xpos = new float[800];
    6. float [] ypos = new float [800];
    7. float [] zpos = new float [800];
    8. Ball[] ballies = new Ball[5];
    9. attractor[] attractor = new attractor[5];

    10. int counter; 


    11. PrintWriter OUTPUT;   

    12. // setup

    13. void keyPressed(){
    14.   if (key == 'r') record = true;
    15.   switch(key){
    16.     case 'i':
    17.     saveFrame("image"+counter+".jpg");
    18.     break;
    19.     case 'b':
    20.     exportBallPoints2Text();
    21.     break;
    22.     case 'a':
    23.     exportAttractorPoints2Text();
    24.     break;
    25.   }
    26.   counter++;
    27. }



    28. void exportBallPoints2Text(){
    29.   OUTPUT = createWriter("Balls"+counter+".txt");
    30.   for (int i=0; i<ballies.length; i++) {
    31.     OUTPUT.println(ballies[i].p.x + "," +  ballies[i].p.y + "," + ballies[i].p.z); 
    32.   }
    33.    counter++;
    34.   OUTPUT.flush();
    35.   OUTPUT.close();
    36.   println("complete success (balls) !");
    37. }

    38. void exportAttractorPoints2Text(){
    39.   OUTPUT = createWriter("attractor"+counter+".txt");
    40.   for (int p=0; p<attractor.length; p++) {
    41.     OUTPUT.println(attractor[p].x + "," +  attractor[p].y + "," + attractor[p].z); 
    42.   }
    43.    counter++;
    44.   OUTPUT.flush();
    45.   OUTPUT.close();
    46.   println("complete success (attractor) !");
    47.  
    48. }




    49. void setup() {
    50.   size(800, 800, P3D);

    51.   cam = new PeasyCam(this, 100);
    52.   cam.setMinimumDistance(100);
    53.   cam.setMaximumDistance(200);




    54.     
    55.     
    56.  if (record) {
    57.     beginRaw(DXF, "output.dxf");
    58.   }

    59.   for (int i=0; i<ballies.length; i++) {
    60.     ballies[i] = new Ball(
    61.     400, 400, random(-10,10), random(-10,10),random(-10,10), 25);
    62.   }
    63.   
    64.         if (record) {
    65.     endRaw();
    66.     record = false;
    67.   }

    68.     for (int p=0; p < attractor.length; p++) {
    69.     attractor[p] = new attractor( width/8 + random(width), height/8 + random(height),  random(50));
    70.     smooth();
    71.   }
    72. }

    73. //........................................................



    74. //........................................................

    75. void draw() {
    76.   background(0);
    77.   stroke(250,250,250);
    78.   strokeWeight(2);
    79.   point(xpos[0], ypos[0], zpos[0]);


    80.   
    81.   
    82.   for (int g = 1; g <800; g++) {
    83.     point(xpos[g], ypos[g], zpos[g]);
    84.   }

    85.   for (int h = 0; h < 100; h++) {//draw x axis
    86.     stroke(255,h*5,0);
    87.     point(h,0,0);
    88.   }

    89.   for (int h = 0; h < 100; h++) {// draw y axis
    90.     stroke(h*5,255,0);
    91.     point(0,h,0);
    92.   }

    93.   for (int h = 0; h < 100; h++) {// draw z axis
    94.     strokeWeight(3);
    95.     stroke(0,255,h*5);
    96.     point(0,0,h);
    97.   }

    98.   for (int i=0; i<ballies.length; i++) { 
    99.     ballies[i].update();
    100.   }
    101.  for (int p=0; p < attractor.length; p++) {
    102.     attractor[p].update();
    103.   }
    104. }

    105. //........................................................ 

    106. class Ball {
    107.   // ball fields
    108.   float x;
    109.   float y;
    110.   float z;
    111.   float speedX;
    112.   float speedY;
    113.   float speedZ;
    114.   float angA;
    115.   float angV = 0;
    116.   boolean dead = false; 
    117.   PVector a; 
    118.   PVector v, p, standardV, offsetV; 


    119.   // ball constructor



    120.   Ball(float _x, float _y, float _z, float _speedX, float _speedY, float _speedZ) {
    121.     p = new PVector(_x, _y, _z);
    122.     v = new PVector(_speedX, _speedY, speedZ);
    123.     standardV = new PVector(_speedX, _speedY, speedZ);
    124.   }


    125.   // ball methods
    126. /*
    127.   void update() {
    128.     position();
    129.     checkCollisions();
    130.     drawBall();
    131.   }
    132.   */
    133.   ///////////////////////////////    
    134.   void update() {
    135.  
    136.     if (!dead) {

    137.       a = new PVector(); 
    138.       for (int i = 0; i < attractor.length; i++) {
    139.           a.add(attractor[i].getAccel(p.x,p.y,p.z));
    140.       }
    141.       
    142.       angA = a.heading2D();
    143.       angV +=  angA/.25;
    144.       v = new PVector( standardV.x, standardV.y, standardV.z); 
    145.       a.normalize();
    146.       a.mult(v.mag());
    147.       a.mult(0.5);
    148.       v.add(a);
    149.      //checkCollisions(); 
    150.       p.add(v);
    151.       angV  *= .9;
    152.     }
    153.     drawBall();
    154.   }


    155.   /////////////////////////////////////      

    156.  void drawBall() {
    157.      
    158.      
    159.   pushMatrix();
    160.     translate( p.x, p.y, p.z);
    161.     
    162. //front    
    163. beginShape(); 
    164. vertex(p.x+25,p.y,p.z+50);
    165. vertex(p.x+25,p.y,p.z);
    166. vertex(p.x+35,p.y,p.z);
    167. vertex(p.x+35,p.y,p.z+65);
    168. vertex(p.x-35,p.y,p.z+65);
    169. vertex(p.x-35,p.y,p.z);
    170. vertex(p.x-25,p.y,p.z);
    171. vertex(p.x-25,p.y,p.z+50);
    172. endShape(CLOSE);

    173. /*
    174. beginShape(); 
    175. vertex(p.x-35,p.y,p.z+65);
    176. vertex(p.x-35,p.y-random(2,10),p.z+65);
    177. vertex(p.x-35,p.y-random(2,10),p.z);
    178. vertex(p.x-35,p.y,p.z);
    179. endShape(CLOSE);
    180. */
    181.     //sphere(5);
    182.     popMatrix();
    183.     

    184.     
    185. }



    186. /*
    187.   void checkCollisions() {
    188.     if(p.x +  v.x > width || p.x + v.x < 0) {
    189.       v.x *= -1;
    190.       standardV.x *= -1; 
    191.     }
    192.     if(p.y + v.y > height || p.y + v.y < 0) {
    193.       v.y *= -1;
    194.     }
    195.     if(p.y + v.y > height || p.y + v.y < 0) {
    196.       v.y *= -1;
    197.     }
    198.   }
    199.   
    200.  */


    201. }



    202. /////////////////////////////////////////////////////

    203. class attractor {
    204.   float x,y,z;

    205.   attractor(float _x, float _y, float _z ) {
    206.     x = _x;
    207.     y = _y;
    208.     z = _z;
    209.   }


    210.   void update() {
    211.     render();
    212.   }
    213.   void render() {
    214.     stroke(255,0,0);
    215.     pushMatrix();
    216.     translate(x,y,z);
    217.     box(5);
    218.     popMatrix();
    219.   }


    220.   PVector getAccel(float px, float py, float pz) {
    221.     PVector a = new PVector(0,0,0); 
    222.     float d2 = sq(dist(px,py,pz,x,y,z));
    223.     if (d2 > 10) {
    224.       a.x = G * (x-px) / d2;
    225.       a.y = G * (y-py) / d2;
    226.       a.z = G * (z-pz) / d2;
    227.     }
    228.     return a;
    229.   }
    230.   
    231. }

    I have been looking at a lot of gravity fields and attractors, but I have yet to see them move in the x,y, and z axis. 

    http://www.openprocessing.org/visuals/?visualID=9151 : this does an awesome job in 2d with 3d representation, and what im looking to do is something similar, but the planets will move in the z direction as well as having fields / attractors scattered about the z axis.

     attached is the code I personally have been working with and creating. My major problem is not knowing how to classify the vectors in 3D, i guess.  I have the attractors scattered in 3D, but the balls keep coming in on 0,0,0 for some reason, and I cannot get any movement to them.

    I have been struggling with this for a few days and so far have gotten nowhere.  if anyone more knowledgeable than me help I will be more than thankful

    import peasy.*;

    PeasyCam cam;

    float [] xpos = new float[800];
    float [] ypos = new float [800];
    float [] zpos = new float [800];
    Ball[] ballies = new Ball[2];
    attractor[] attractor = new attractor[25];


    void setup() {
     size(800, 800, P3D);

     smooth(); 

     cam = new PeasyCam(this, 100);
     cam.setMinimumDistance(100);
     cam.setMaximumDistance(200);
     
       for (int i=0; i<ballies.length; i++) {
        ballies[i] = new Ball(random(width), random(height), random(10), random(20),random(80,2),random(90,2),50);
      }
      
      for (int p=0; p < attractor.length; p++) {
        attractor[p] = new attractor( width/8 + random(width), height/8 + random(height),   random(300));
        smooth();
      }
    }

    void draw() {
     background(0);
     stroke(250,250,250);
     strokeWeight(2);
     point(xpos[0], ypos[0], zpos[0]);

     for (int g = 1; g <800; g++){
       point(xpos[g], ypos[g], zpos[g]);
     }

     for (int h = 0; h < 100; h++){//draw x axis
       stroke(255,h*5,0);
       point(h,0,0);
     }

     for (int h = 0; h < 100; h++){// draw y axis
       stroke(h*5,255,0);
       point(0,h,0);
     }

     for (int h = 0; h < 100; h++){// draw z axis
       strokeWeight(3);
       stroke(0,255,h*5);
       point(0,0,h); 
     }
     
       for (int p=0; p < attractor.length; p++) {
        attractor[p].update();
      }
      
       for (int i=0; i<ballies.length; i++) { 
        ballies[i].update();
      }
      
    }

    class Ball {
      // ball fields
      float x;
      float y;
      float z;
      float speedX;
      float speedY;
      float speedZ;
      int normSize;
      float angA;
      float angV = 0;
      boolean dead = false; 
      PVector a; 
      PVector v, p, standardV, offsetV; 


      // ball constructor



      Ball(float _x, float _y, float _z, float _speedX, float _speedY, float _speedZ, int _normSize) {
        p = new PVector(_x, _y, _z);
        v = new PVector(_speedX, _speedY, _speedZ);
        standardV = new PVector(_speedX, _speedY, _speedZ);
        normSize  = _normSize;
      }

      void update() {
     
        if (!dead) {

          a = new PVector(); 
          for (int i = 0; i < attractor.length; i++) {
              a.add(attractor[i].getAccel(p.x,p.y,p.z));
            }
        
          //angA = a.heading2D();
          angV +=  angA/.25;
          v = new PVector( standardV.x, standardV.y, standardV.z); 
          a.normalize();
          a.mult(v.mag());
          a.mult(0.9);
          v.add(a);
          checkCollisions(); 
          p.add(v);
          angV  *= 12;
        }
       drawBall();
      }
      
        void drawBall() {
        pushMatrix();
        translate(x,y,z);
        sphere(1);
        popMatrix();
    }

      void checkCollisions() {
        if(p.x +  v.x > width || p.x + v.x < 0) {
          v.x *= -1;
          standardV.x *= -1; 
        }
        if(p.y + v.y > height || p.y + v.y < 0) {
          v.y *= -1;
        }
         if(p.z + v.z > height || p.z + v.z < 0) {
          v.z *= -1;
        }
      }
    }

    /////////////////////////////////////////////////////

    class attractor {
      float x,y,z;

      attractor(float _x, float _y, float _z ) {
        x = _x;
        y = _y;
        z = _z;
      }


      void update() {
        render();

      
      }
      void render() {
        stroke(255,0,0);
        pushMatrix();
        translate(x,y,z);
        box(5);
        popMatrix();
      }
      
      
      PVector getAccel(float px, float py, float pz) {
        PVector a = new PVector(0,0,0); 
        float d2 = sq(dist(px,py,pz,x,y,z));
        if (d2 > 10) {
          a.x = G * (x-px) / d2;
          a.y = G * (y-py) / d2;
          a.z = G * (z-pz) / d2;
        }
        return a;
      }
      
    }

    So i took a code i had written for a 2D space, and used a peasy cam, and have since brought it to the 3d environment.  The only problem is i cannot get the ball to move around the space towards the attractors.  any help?


    import peasy.*;

    PeasyCam cam;

    float [] xpos = new float[7000];
    float [] ypos = new float [7000];
    float [] zpos = new float [7000];
    Ball[] ballies = new Ball[2];
    attractor[] attractor = new attractor[25];


    void setup() {
     size(800, 800, P3D);

     smooth(); 

      cam = new PeasyCam(this, 100);
     cam.setMinimumDistance(100);
     cam.setMaximumDistance(200);
     
       for (int i=0; i<ballies.length; i++) {
        ballies[i] = new Ball(random(width), random(height), random(300), random(0,2),random(0,2),25,50);
      }
      
      for (int p=0; p < attractor.length; p++) {
        attractor[p] = new attractor( width/8 + random(width), height/8 + random(height),   random(300));
        smooth();
      }
    }

    void draw() {
     background(0);
     stroke(250,250,250);
     strokeWeight(2);
     point(xpos[0], ypos[0], zpos[0]);

     for (int g = 1; g <5000; g++){
       point(xpos[g], ypos[g], zpos[g]);
     }

     for (int h = 0; h < 100; h++){//draw x axis
       stroke(255,h*5,0);
       point(h,0,0);
     }

     for (int h = 0; h < 100; h++){// draw y axis
       stroke(h*5,255,0);
       point(0,h,0);
     }

     for (int h = 0; h < 100; h++){// draw z axis
       strokeWeight(3);
       stroke(0,255,h*5);
       point(0,0,h); 
     }
     
       for (int p=0; p < attractor.length; p++) {
        attractor[p].update();
      }
      
       for (int i=0; i<ballies.length; i++) { 
        ballies[i].update();
      }
      
    }

    class Ball {
      // ball fields
      float x;
      float y;
      float z;
      float speedX;
      float speedY;
      float speedZ;
      int normSize;
      float angA;
      float angV = 0;
      boolean dead = false; 
      PVector a; 
      PVector v, p, standardV, offsetV; 


      // ball constructor



      Ball(float _x, float _y, float _z, float _speedX, float _speedY,float _speedZ, int _normSize) {
        p = new PVector(_x, _y, _z);
        v = new PVector(_speedX, _speedY, _speedZ);
        standardV = new PVector(_speedX, _speedY, _speedZ);
        normSize  = _normSize;
      }

      void update() {
     
        if (!dead) {

          a = new PVector(); 
          for (int i = 0; i < attractor.length; i++) {
              a.add(attractor[i].getAccel(p.x,p.y,p.z));
            }
        
          angA = a.heading2D();
          angV +=  angA/.25;
          v = new PVector( standardV.x, standardV.y, standardV.z); 
          a.normalize();
          a.mult(v.mag());
          a.mult(0.9);
          v.add(a);
          checkCollisions(); 
          p.add(v);
          angV  *= .9;
        }
       drawBall();
      }
      
        void drawBall() {
        pushMatrix();
        translate(x,y,z);
        sphere(2);
        popMatrix();
    }

      void checkCollisions() {
        if(p.x +  v.x > width || p.x + v.x < 0) {
          v.x *= -1;
          standardV.x *= -1; 
        }
        if(p.y + v.y > height || p.y + v.y < 0) {
          v.y *= -1;
        }
         if(p.z + v.z > height || p.z + v.z < 0) {
          v.z *= -1;
        }
      }
    }

    /////////////////////////////////////////////////////

    class attractor {
      float x,y,z;

      attractor(float _x, float _y, float _z ) {
        x = _x;
        y = _y;
        z = _z;
      }


      void update() {
        render();

      
      }
      void render() {
        stroke(255,0,0);
        pushMatrix();
        translate(x,y,z);
        box(5);
        popMatrix();
      }
      
      
      PVector getAccel(float px, float py, float pz) {
        PVector a = new PVector(0,0,0); 
        float d2 = sq(dist(px,py,pz,x,y,z));
        if (d2 > 10) {
          a.x = G * (x-px) / d2;
          a.y = G * (y-py) / d2;
          a.z = G * (z-pz) / d2;
        }
        return a;
      }
      
    }

    Hey all.  Thanks a lot with my last question, I ended up getting that to work.  A
    nyway, have a new one now.  I'm working on splicing a code to export points into the existing code i am working on, and it runs, and it looks right, and it tells me the points have been exported... but in the file folder for the code is a zero kb "exportedpoints.txt"

    anyone offer any help?


    Code:

    Ball[] ballies = new Ball[75];
    attractor[] attractor = new attractor[25];


    //........................................................
    ArrayList pointList;     // arraylist to store the points in
    PrintWriter OUTPUT;       // an instantiation of the JAVA PrintWriter object.
                              // This variable reappears in our custom export function 
    //........................................................

    // setup
    //........................................................


    void setup() {
      size(800, 800);
      background(255);

    //........................................................
      pointList = new ArrayList();    // instantiate an ArrayList
    //........................................................

      for (int i=0; i<ballies.length; i++) {
        ballies[i] = new Ball(
        random(width), random(height), random(0,2),random(0,0),25);
      }
      for (int p=0; p < attractor.length; p++) {
        attractor[p] = new attractor( width/8 + random(width), height/8 + random(height)  );
        smooth();
      }
      //........................................................
         for(int i = 0; i < pointList.size(); ++i){        
        PVector V = (PVector) pointList.get(i);
        ellipse(V.x,V.y, 8.0, 8.0);
      }
    //........................................................ x
    }

     
      
      
    void mousePressed() {
      setup();
    }

    //........................................................
    void keyPressed(){
      switch(key){
        case 's':
        saveFrame("importedPoints.jpg");
        break;
        case 'x':
        exportPoints2Text();
        break;
      }
    }


    void exportPoints2Text(){
      OUTPUT = createWriter("exportedPoints.txt");
      for(int i = 0; i < pointList.size(); ++i){        
        PVector V = (PVector) pointList.get(i);
        OUTPUT.println(V.x + "" + V.y + "," + V.z);  // here we export the coordinates of the vector using String concatenation!
      }
      OUTPUT.flush();
      OUTPUT.close();
      println("points have been exported");
    }
    //........................................................

    void draw() {

      for (int i=0; i<ballies.length; i++) { 
        ballies[i].update();
      }


      for (int p=0; p < attractor.length; p++) {
        attractor[p].update();
      }
    }

    //........................................................ 

    class Ball {
      // ball fields
      float x;
      float y;
      float speedX;
      float speedY;
      int normSize;
      float angA;
      float angV = 0;
      boolean dead = false; 
      PVector a; 
      PVector v, p, standardV, offsetV; 


      // ball constructor



      Ball(float _x, float _y, float _speedX, float _speedY, int _normSize) {
        p = new PVector(_x, _y);
        v = new PVector(_speedX, _speedY);
        standardV = new PVector(_speedX, _speedY);
        normSize  = _normSize;
      }


      // ball methods
    /*
      void update() {
        position();
        checkCollisions();
        drawBall();
      }
      */
      ///////////////////////////////    
      void update() {
     
        if (!dead) {

          a = new PVector(); 
          for (int i = 0; i < attractor.length; i++) {
            if (dist(p.x, p.y, attractor[i].x, attractor[i].y) < 200) { 
              stroke(#ff0000, 2.5);
              line(p.x, p.y, attractor[i].x, attractor[i].y);
              a.add(attractor[i].getAccel(p.x,p.y));
            }
          }
          angA = a.heading2D();
          angV +=  angA/.25;
          // render();
          v = new PVector( standardV.x, standardV.y); 
          a.normalize();
          a.mult(v.mag());
          a.mult(0.9);
          v.add(a);
          checkCollisions(); 
          p.add(v);
          angV  *= .9;
        }
        drawBall();
      }


      /////////////////////////////////////      



      void drawBall() {
        stroke(0);
        strokeWeight(.05);
        //ellipse(p.x, p.y, 25, 25);
        point  (p.x, p.y);
    }

      void checkCollisions() {
        if(p.x +  v.x > width || p.x + v.x < 0) {
          v.x *= -1;
          standardV.x *= -1; 
        }
        if(p.y + v.y > height || p.y + v.y < 0) {
          v.y *= -1;
        }
      }
    }

    ////////////////////////////////////////////////////////////////////


    class attractor {
      float x,y;

      attractor(float _x, float _y ) {
        x = _x;
        y = _y;
      }

      void update() {
        render();
      }
      void render() {
        stroke(255,0,0);
      }
      PVector getAccel(float px, float py) {
        PVector a = new PVector(0,0,0); 
        float d2 = sq(dist(px,py,x,y));
        if (d2 > 10) {
          a.x = G * (x-px) / d2;
          a.y = G * (y-py) / d2;
        }
        return a;
      }
    }

    i hav ebeen playing around with the original flocking script and am trying to get the fill of the boids to leave a trail behind them.  any help?
    THANKS

    Flock flock;

    void setup() {
      size(640, 360);
      flock = new Flock();
      // Add an initial set of boids into the system
      for (int i = 0; i < 250; i++) {
        flock.addBoid(new Boid(new PVector(width/2,height/2), 3.0, 0.05));
      }
      smooth();
    }

    void draw() {
      background(255);
      flock.run();
    }

    // Add a new boid into the System
    void mousePressed() {
      flock.addBoid(new Boid(new PVector(mouseX,mouseY),23.0f,0.05f));
    }



    // The Boid class

    class Boid {

      PVector loc;
      PVector vel;
      PVector acc;
      
      float r;
      float maxforce;    // Maximum steering force
      float maxspeed;    // Maximum speed

        Boid(PVector l, float ms, float mf) {
        acc = new PVector(0,0);
        vel = new PVector(random(-.5,.5),random(-.5,.5));
        loc = l.get();
        r = 4;
        maxspeed = ms;
        maxforce = mf;
      }

      void run(ArrayList boids) {
        flock(boids);
        update();
        borders();
        render();
      }

      // We accumulate a new acceleration each time based on three rules
      void flock(ArrayList boids) {
        PVector sep = separate(boids);   // Separation
        PVector ali = align(boids);      // Alignment
        PVector coh = cohesion(boids);   // Cohesion
        // Arbitrarily weight these forces
        sep.mult(1.5);
        ali.mult(1.0);
        coh.mult(1.0);
        // Add the force vectors to acceleration
        acc.add(sep);
        acc.add(ali);
        acc.add(coh);
      }

      // Method to update location
      void update() {
        // Update velocity
        vel.add(acc);
        // Limit speed
        vel.limit(maxspeed);
        loc.add(vel);
        // Reset accelertion to 0 each cycle
        acc.mult(0);

      }
     

      void seek(PVector target) {
        acc.add(steer(target,false));
      }

      void arrive(PVector target) {
        acc.add(steer(target,true));
      }

      // A method that calculates a steering vector towards a target
      // Takes a second argument, if true, it slows down as it approaches the target
      PVector steer(PVector target, boolean slowdown) {
        PVector steer;  // The steering vector
        PVector desired = target.sub(target,loc);  // A vector pointing from the location to the target
        float d = desired.mag(); // Distance from the target is the magnitude of the vector
        // If the distance is greater than 0, calc steering (otherwise return zero vector)
        if (d > 0) {
          // Normalize desired
          desired.normalize();
          // Two options for desired vector magnitude (1 -- based on distance, 2 -- maxspeed)
          if ((slowdown) && (d < 100.0)) desired.mult(maxspeed*(d/100.0)); // This damping is somewhat arbitrary
          else desired.mult(maxspeed);
          // Steering = Desired minus Velocity
          steer = target.sub(desired,vel);
          steer.limit(maxforce);  // Limit to maximum steering force
        } 
        else {
          steer = new PVector(0,0);
        }
        return steer;
      }

      void render() {
        // Draw a triangle rotated in the direction of velocity
        float theta = vel.heading2D() + PI/2;
        fill(100,100,100,100);
        //stroke(1); //255
        //strokeWeight(1);
        pushMatrix();
        translate(loc.x,loc.y);
        rotate(theta);
        ellipse(0, 0, .5, .5);
       // point (loc.x,loc.y);
        popMatrix();
      }

      // Wraparound
      void borders() {
        if (loc.x < -r) loc.x = width+r;
        if (loc.y < -r) loc.y = height+r;
        if (loc.x > width+r) loc.x = -r;
        if (loc.y > height+r) loc.y = -r;
      }

      // Separation
      // Method checks for nearby boids and steers away
      PVector separate (ArrayList boids) {
        float desiredseparation = 20.0;
        PVector steer = new PVector(0,0,0);
        int count = 0;
        // For every boid in the system, check if it's too close
        for (int i = 0 ; i < boids.size(); i++) {
          Boid other = (Boid) boids.get(i);
          float d = PVector.dist(loc,other.loc);
          // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
          if ((d > 0) && (d < desiredseparation)) {
            // Calculate vector pointing away from neighbor
            PVector diff = PVector.sub(loc,other.loc);
            diff.normalize();
            diff.div(d);        // Weight by distance
            steer.add(diff);
            count++;            // Keep track of how many
          }
        }
        // Average -- divide by how many
        if (count > 0) {
          steer.div((float)count);
        }

        // As long as the vector is greater than 0
        if (steer.mag() > 0) {
          // Implement Reynolds: Steering = Desired - Velocity
          steer.normalize();
          steer.mult(maxspeed);
          steer.sub(vel);
          steer.limit(maxforce);
        }
        return steer;
      }

      // Alignment
      // For every nearby boid in the system, calculate the average velocity
      PVector align (ArrayList boids) {
        float neighbordist = 25.0;
        PVector steer = new PVector(0,0,0);
        int count = 0;
        for (int i = 0 ; i < boids.size(); i++) {
          Boid other = (Boid) boids.get(i);
          float d = PVector.dist(loc,other.loc);
          if ((d > 0) && (d < neighbordist)) {
            steer.add(other.vel);
            count++;
          }
        }
        if (count > 0) {
          steer.div((float)count);
        }

        // As long as the vector is greater than 0
        if (steer.mag() > 0) {
          // Implement Reynolds: Steering = Desired - Velocity
          steer.normalize();
          steer.mult(maxspeed);
          steer.sub(vel);
          steer.limit(maxforce);
        }
        return steer;
      }

      // Cohesion
      // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
      PVector cohesion (ArrayList boids) {
        float neighbordist = 25.0;
        PVector sum = new PVector(0,0);   // Start with empty vector to accumulate all locations
        int count = 0;
        for (int i = 0 ; i < boids.size(); i++) {
          Boid other = (Boid) boids.get(i);
          float d = loc.dist(other.loc);
          if ((d > 0) && (d < neighbordist)) {
            sum.add(other.loc); // Add location
            count++;
          }
        }
        if (count > 0) {
          sum.div((float)count);
          return steer(sum,false);  // Steer towards the location
        }
        return sum;
      }
    }





    // The Flock (a list of Boid objects)

    class Flock {
      ArrayList boids; // An arraylist for all the boids

      Flock() {
        boids = new ArrayList(); // Initialize the arraylist
      }

      void run() {
        for (int i = 0; i < boids.size(); i++) {
          Boid b = (Boid) boids.get(i);  
          b.run(boids);  // Passing the entire list of boids to each boid individually
        }
      }

      void addBoid(Boid b) {
        boids.add(b);
      }