Loading...
Logo
Processing Forum
miles.tone's Profile
11 Posts
28 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
            Hi All sorry about the quote marks <<<

      1. int stRad = 100;
      2. SoundCircle SC;
      3. float angle=HALF_PI + PI;
      4. PGraphics waveForm;
      5. float seg=0;
      6. int segalpha;

      7. void setup() {
      8.   size(800, 800, P2D);
      9.   smooth();
      10.   frameRate(60);
      11.   stroke(250);
      12.   background(0);

      13.   
      14.   SC= new SoundCircle(width/2,height/2);
      15.   imageMode(CENTER);
      16.     waveForm  = createGraphics(width,height, P2D);

      17.  void draw() {
      18.   
      19.      
      20.     
      21.     SC.waveform();
      22.     SC.display();
      23.     
      24.      
      25.       
      26.     
      27. }

      28. class SoundCircle{
      29.      int cx;
      30.      int cy;
      31.      float buffCircle,buffAngle,bbuffAngle,abuffAngle,ax,ay,x,y,bx,by;
      32.      
      33.     SoundCircle(int tempx, int tempy){
      34.      cx = tempx;
      35.      cy = tempy;
      36.   
      37.      
      38.     }
      39.      
      40.    void waveform(){
      41.     float r = liveamp + 100.00;
      42.      buffCircle = TWO_PI/240.0;
      43.      buffAngle=buffCircle*frameCount;
      44.      bbuffAngle=buffCircle*(frameCount+1);
      45.      abuffAngle=buffCircle*(frameCount-1);
      46.       if (buffAngle <= TWO_PI) {
      47.       ax = cx + stRad * cos(buffAngle);
      48.       ay = cy + stRad * sin(buffAngle);
      49.       x = cx + r * cos(abuffAngle);
      50.       y = cy + r * sin(abuffAngle);
      51.       bx = cx + stRad * cos(bbuffAngle);
      52.       by = cy + stRad * sin(bbuffAngle);
      53.     
      54.   }
      55.       
      56.     
      57.     
      58.     }
      59.     
      60.       
      61.       void display(){
      62.         
      63.      
      64.       waveForm.beginDraw();
      65.       waveForm.stroke(250);
      66.       waveForm.beginShape(LINES);
      67.       waveForm.vertex(ax, ay);
      68.       waveForm.vertex(x, y);
      69.       waveForm.vertex(x, y);
      70.       waveForm.vertex(bx, by);
      71.       waveForm.endShape(CLOSE);
      72.       waveForm.endDraw();

      1. imageMode(CENTER);
      2.       translate(cx,cy);
      3.       
      4.        rotate(angle);
      5.       
      6.       image(waveForm, 0,0);
      Im guessing this is a horrible way to obliterate CPU

      Do you know anyway to lower the CPU usage?

      Many Thanks
      Miles

      Hi All

      We’ve made a  Processing and PD desktop application using libpd, and now were trying to compile it for android.

      I’m using Processing 1.5.1, Eclipse Indigo 3.7 and have installed Android SDK r15 with API’s 7&8 on my Mac.

      In processing i can run a virtual device, but only through the AVD manager.When i try and run any sketch in android mode i get an error message that comes up with “Error from inside the Android tools” then in the console it says that the build.xml file is obsolete.

      When i access Pd Android example files in Eclipse the whole src file shows errors even after i clean the project.

      If anybody has any info/resources that could help us out it would be very much appreciated

      Many Thanks

      Miles

      Im attempting to implement a 3rd party library.
      The examples work fine, however, when i run my code i get the error:
      "Invalid memory access of location 0x0 eip=0x220fdbb1"
      I then get an apple report saying that one of the dynamic libraries im using has quit unexpectedly
      Does anyone have an inkling as to what this could be
      Many Thanks
      Miles
      Hi there,
      I'm trying to have a resizable rectangle that acts as a mask over the top waveform, however i just keep on creating new rectangles on top, I'm sure I've just called something wrong somewhere.

      1. float x,y,ax,ay,bx,by;
      2. int stRad;
      3. WFormMask myWFormMask;



      4. void setup() {
      5.   size(800,800);
      6.   smooth();
      7.   frameRate(60);
      8.   stroke(250);
      9.   background(0);
      10.   stRad=100;
      11.   myWFormMask = new WFormMask(0);
      12. }

      13. void draw() {
      14.   

      15.  int cx = width/2;
      16.  int cy = height/2;
      17.     float r = random(50,100)+random(1,50);
      18.  float buffCircle = TWO_PI/240.0;
      19.     float buffAngle=buffCircle*frameCount;
      20.     float bbuffAngle=buffCircle*(frameCount+1);
      21.     float abuffAngle=buffCircle*(frameCount-1);
      22.  if(buffAngle <= TWO_PI){
      23.      ax = cx + stRad * cos(buffAngle);
      24.  ay = cy + stRad * sin(buffAngle);
      25.   x = cx + r * cos(abuffAngle);
      26.  y = cy + r * sin(abuffAngle);
      27.    bx = cx + stRad * cos(bbuffAngle);
      28.  by = cy + stRad * sin(bbuffAngle);
      29.  beginShape(LINES);
      30. vertex(ax,ay);
      31. vertex(x,y);
      32. vertex(x,y);
      33. vertex(bx,by);
      34. endShape();
      35.  }
      36.  float currentHor= (3.33333333333333333333)*frameCount;    ///////width/(frameRate*seconds) = 3.3333333333//////
      37.   float acurrentHor= (3.33333333333333333333)*(frameCount+1);
      38.   float bcurrentHor= 3.33333333333333333333*(frameCount-1);
      39.  if (currentHor<=800){
      40.    stroke(250);
      41.    beginShape(LINES);
      42.          vertex(bcurrentHor,stRad);
      43.    vertex(currentHor,r);
      44.    vertex(currentHor,r);
      45.   vertex(acurrentHor,stRad);
      46.  endShape();
      47. }
      48. }
      49. void mousePressed(){
      50.   if(mouseY<=200){
      51.   int  mScrubPoint = mouseX;

      52.  myWFormMask.display(mScrubPoint);
      53.   }
      54. }

      55. class WFormMask{
      56.   int xpos;
      57.   
      58.   WFormMask(int tempXpos) { 
      59.      xpos = tempXpos;
      60.   }

      61.   void display(int xpos) {
      62.     stroke(0);
      63.     fill(random(0,250));
      64.     rect(0,0,xpos,200);
      65.   }
      66. }
      Many Thanks
      Miles
      I have an arrayList of clickable balls, i don't mind them overlapping, but its a problem when they clump when clicked or when a smaller ball is obscured by a larger one. What would be the best way to sort this?
      an array list of the balls ordered by size so they are drawn in order?
      Many Thanks
      Miles
      Hiya
      In my current sketch I'm using an array of balls, i need to be able to send the ball ID over OSC, i also need to be able to add and delete balls. Obviously i can add whilst using an array but I'm unsure as to whether or not i need to completely change all of the array stuff in my sketch and replace it with array list functions. Can i use an array list to manage my array?
      Basically shall i swap my array for an array list or shall i house and manage my array within an array list?

      Many Thanks
      Hi there,
      Im trying to make a simple honeycomb structure
      I keep on going round in circles, I'm missing one simple computation somewhere.

      Heres the code:

      1. Hexagon[][] hexagon;
        int rad = 50;
        int hexcountx, hexcounty;

        void setup()
        {
          size(300, 300);
          background(255);
          smooth();
          noFill();
          stroke(0);
          hexcountx = (height/(rad*2));
          hexcounty = (width/(rad*2));
          hexagon = new Hexagon [hexcountx][hexcounty];
          for (int i = 0; i < hexcountx; i++){
            for (int j = 0; j < hexcounty; j++){
          hexagon[i][j] = new Hexagon((2*rad*i), (rad*j), rad);
        }
        }
        }
        void draw(){
          for (int i = 0; i < hexcountx; i ++ ) {     
            for (int j = 0; j < hexcounty; j ++ ) {
              // Oscillate and display each object
              hexagon[i][j].display();
            }
          }
        }

         class Hexagon{
           float x,y,radi;
             float angle = 360.0 / 6;
           
         Hexagon(float cx, float cy, float r)
        {
          x=cx;
          y=cy;
          radi=r;
        }

         void display(){
         beginShape();
          for (int i = 0; i < 6; i++)
          {
            vertex(x + radi * cos(radians(angle * i)),
              y + radi * sin(radians(angle * i)));
          }
          endShape(CLOSE);
        }
        }



      All the best
      Miles
      Hi There
      I can get my sketch sending but not recieving, it did receive for a while, but not anymore.
      Heres how im receiving the data, the inputs are ints
      1. void oscEvent(OscMessage theOscMessage)
      2. {
      3.   oscP5.plug(this,"freq1","/freq1");
      4.   oscP5.plug(this, "freq2", "/freq2");
      5.   oscP5.plug(this, "amp1", "/amp1"); 
      6.   oscP5.plug(this, "amp2", "/amp2");
      7. }
      I think ive missed something obvious.
      Any help would be kindly appreciated
      Thanks
      MT
      Hi All
      I have this piece of code, ive never really used arrays before and ive been quite stuck on this, im using color tracking to move an array of ellipses around (16 of them), but it just continually draws more ellipses, if anyone can show me how to correct this so it is just an trail of 16 i would be greatly appreciative
      heres the code:
      1. int colorX = 0; // X-coordinate of the closest in color video pixel
      2. int colorY = 0; // Y-coordinate of the closest in color video pixel
      3. int activetoggle = 0;
      4. import oscP5.*;
      5. import netP5.*;
      6. boolean active = false;
      7. OscP5 oscP5;
      8. NetAddress myRemoteLocation;
      9. import processing.video.*;
      10. Capture video;
      11. int g = 0;
      12. int ay = 0;
      13. int ax = 0;
      14. int[] trail_x;
      15. int[] trail_y;
      16. int tindex = 0;
      17. int ellipsearrayY;

      18. void setup(){
      19.  
      20.   size(600,600);
      21.   background (0);
      22.   video = new Capture(this, width, height, 30);
      23.   smooth();
      24.   println(Capture.list());
      25.   /* Frame rate is 30 */
      26.   /* The fill color is set to black (0) for the boundaries (drawn as a quad) */
      27.   oscP5 = new OscP5(this,7474);
      28.   myRemoteLocation = new NetAddress("127.0.0.1",7474);
      29.   frameRate(30);
      30.     trail_x = new int[16];
      31.   trail_y = new int[16];
      32. }
      33.  
      34.  
      35.  
      36. void draw(){
      37.   if (video.available()) {
      38.     video.read();
      39.     video.loadPixels();
      40.     int index = 0;
      41.     for (int ay = 0; ay < video.height; ay++) {
      42.       for (int ax = 0; ax < video.width; ax++) {
      43.         // Get the color stored in the pixel
      44.         
      45.     color argb = video.pixels[index];
      46. int a = (argb >> 24) & 0xFF;
      47. int r = (argb >> 16) & 0xFF;  
      48. int g = (argb >> 8) & 0xFF;   
      49. int b = argb & 0xFF;       

      50.       
      51. if (g>200){
      52.   active = true;
      53.   colorY = ay;
      54.           colorX = ax;
      55.           activetoggle = 1;
      56.           
      57.       }
      58.       index++;
      59.      
      60.     
      61.     }

      62. color activetest = video.pixels[colorY*width+colorX];
      63. if (((activetest >> 8) & 0xFF)<200){
      64. active = false;
      65. activetoggle = 0;
      66. }  

      67.     
      68.   }
      69.    
      70.  if (active ==true){
      71.    trail_x[tindex] = colorX;
      72.   trail_y[tindex] = colorY;
      73.   tindex++;
      74.   if (tindex >= trail_x.length) tindex = 0;
      75.  for (int i=0; i < trail_x.length; i++) {
      76.      
      77.     // always end with the last mouse position to avoid the "jumping"
      78.     // effect
      79.     int pos = (tindex+i) % trail_x.length;
      80.     //int pos = i;
      81.      
      82.     // we can use the counter for color and size
      83.     ellipse(trail_x[pos], trail_y[pos], 50, 50); 
      84.      int ellipsearrayY = trail_y[pos];
      85.   }
      86.  }
      87.  
      88. OscMessage myMessage = new OscMessage("/test");     
      89.     myMessage.add((int)ellipsearrayY);
      90.     myMessage.add((int)colorY);
      91.     myMessage.add((int)activetoggle);
      92.     myMessage.add((int)g);   
      93.     /* send the message */
      94.     oscP5.send(myMessage, myRemoteLocation);
      95.  }
      Many Thanks
      Miles
      Hi there,
      Im making a bit shift colour tracker with a toggle that'll switch around a colour threshold.
      At the moment ive got to the point where i can track the colours, but i cant get the toggle to work,
      Im trying to test the tracked pixel to see if it is green enough using:
      1. for (color activetest = video.pixels[colorY*width+colorX]; ((activetest >> 8) & 0xFF)<200;){
      2.  active = false;
      3. activetoggle = 0;
      but im quite new to this all, so i expect im doing something silly, but i can't work out what, this bit of code either returns a nullpointerexpression, or freezes the image.

      Heres the rest of the code which works:
      1. int colorX = 0; // X-coordinate of the closest in color video pixel
      2. int colorY = 0; // Y-coordinate of the closest in color video pixel
      3. float activetoggle = 0;
      4. import oscP5.*;
      5. import netP5.*;
      6. boolean active = false;
      7. OscP5 oscP5;
      8. NetAddress myRemoteLocation;
      9. import processing.video.*;
      10. Capture video;
      11. int g;
      12. int ay;
      13. int ax;

      14. void setup(){
      15.  
      16.   size(600,600);
      17.   video = new Capture(this, width, height, 30);
      18.   smooth();
      19.   /* Frame rate is 30 */
      20.   /* The fill color is set to black (0) for the boundaries (drawn as a quad) */
      21.   oscP5 = new OscP5(this,7474);
      22.   myRemoteLocation = new NetAddress("127.0.0.1",7474);
      23.   frameRate(30);
      24. }
      25.  
      26.  
      27.  
      28. void draw(){
      29.   if (video.available()) {
      30.     video.read();
      31.     image(video, 0, 0, width, height);
      32.     video.loadPixels();
      33.     int index = 0;
      34.     for (int ay = 0; ay < video.height; ay++) {
      35.       for (int ax = 0; ax < video.width; ax++) {
      36.         // Get the color stored in the pixel
      37.         
      38.     color argb = video.pixels[index];
      39. int a = (argb >> 24) & 0xFF;
      40. int r = (argb >> 16) & 0xFF;  
      41. int g = (argb >> 8) & 0xFF;   
      42. int b = argb & 0xFF;       
      43. if (g>200){
      44.   active = true;
      45.   colorY = ay;
      46.           colorX = ax;
      47.           activetoggle = 1;
      48.           
      49.       }
      50.       index++;
      51.      
      52.     }
      53.     }
      54.       
      55.   

      56. OscMessage myMessage = new OscMessage("/test");     
      57.     myMessage.add((int)colorX);
      58.     myMessage.add((int)colorY);
      59.     myMessage.add((float)activetoggle);   
      60.     /* send the message */
      61.     oscP5.send(myMessage, myRemoteLocation);
      62.     
      63.   }
      64. }

      Any help would be greatly appreciated.
      Thanks
      MilesTone
      Hi there, 
      Im a beginner with processing and really want to sink my teeth into it, im having a problem with the sketch im using,im trying to use the x y data from the color tracking within the particle class afterwards.
      I think im close to getting it working but ive got stuck as im being told that im mixing active and static modes
      Really need some help with this and it will be huuuugely appreciated.

      Heres the code:

      1. /**
      2. * Color Tracking
      3. * by Justin Brooks
      4. *
      5. *
      6. * based on original code:
      7. *   Brightness Tracking 
      8. *   by Golan Levin. 
      9. * Tracks the tracks pixel closest in color to specified color.
      10. */
      11. boolean lines = false;
      12. /*
      13. gravity toggle
      14. toggle this by pressing 'g'
      15. */
      16. boolean gravity = true;
      17. /* Particle count */
      18. int particleCount = 500;
      19. /* Particle array */
      20. Particle[] particles = new Particle[particleCount+1];

      21. import processing.video.*;

      22. Capture video;

      23. void setup() {
      24.  size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
      25.  // Uses the default video input, see the reference if this causes an error
      26.  video = new Capture(this, width, height, 30);
      27.  noStroke();
      28.  smooth();
      29.  colorMode(RGB, 400);
      30.   /* Frame rate is 30 */
      31.   frameRate(30);
      32.   /* The fill color is set to black (0) for the boundaries (drawn as a quad) */
      33.   fill (0);
      34.   coordx = new Particle (colorX);
      35.   coordy = new Particle (colorY);
      36.   /* We loop through our particle count and initialize each */
      37.   for (int x = particleCount; x >= 0; x--) {
      38.     particles[x] = new Particle();
      39.   }
      40. }

      41. void draw() {
      42.  if (video.available()) {
      43.    video.read();
      44.    background(0);
      45.   /* The stroke color is set to white for the border. */
      46.   stroke (400);
      47.   /* The border; it is 10 pixels from all sides */
      48.   quad (10,10,10,height-10,width-10,height-10,width-10,10); 
      49.   /* All of our particles are looped through, and updated */
      50.   for (int i = particleCount; i >= 0; i--) {
      51.     Particle particle = (Particle) particles[i];
      52.     particle.update(i);
      53.   }
      54.    int colorX = 0; // X-coordinate of the closest in color video pixel
      55.    int colorY = 0; // Y-coordinate of the closest in color video pixel
      56.    float closestColor = 10000; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value
      57.    // Search for the closest in color pixel: For each row of pixels in the video image and
      58.    // for each pixel in the yth row, compute each pixel's index in the video
      59.    video.loadPixels();
      60.    int index = 0;
      61.    for (int ay = 0; ay < video.height; ay++) {
      62.      for (int ax = 0; ax < video.width; ax++) {
      63.        // Get the color stored in the pixel
      64.        color pixelValue = video.pixels[index];
      65.        // Determine the color of the pixel
      66.        float colorProximity = abs(red(pixelValue)-0)+abs(green(pixelValue)-255)+abs(blue(pixelValue)-0);
      67.        // If that value is closer in color value than any previous, then store the
      68.        // color proximity of that pixel, as well as its (x,y) location
      69.        if (colorProximity < closestColor) {
      70.          closestColor = colorProximity;
      71.          closestColor=closestColor-10; //thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along
      72.          colorY = ay;
      73.          colorX = ax;
      74.        }
      75.        index++;
      76.      }
      77.    }
      78.    // Draw a large, yellow circle at the brightest pixel
      79.    fill(255, 204, 0, 128);
      80.    ellipse(colorX, colorY, 200, 200);
      81.  }
      82. }

      83. class Particle {
      84.   /*
      85.   Global class variables
      86.   These are kept track of, and aren't lost when the class particle is finished operating.
      87.   */
      88.   /* the x and y are our coordinates for each particles */
      89.   Particle () {
      90.     float coordx;
      91.   float coordy;

      92.      mx = coordx; 
      93. my = coordy;
      94.   }
      95. }
      96.   float x;
      97.   float y;
      98.   /* vx and vy are the velocities along each axis the particles are traveling */
      99.   float vx;
      100.   float vy;
      101.   /* Particle initialization. We define the beginning properties of each particle here. */
      102.   Particle() {
      103.     x = random(10,width-10);
      104.     y = random(10,height-10);
      105.   }
      106.   /* These are called everytime we check with the other particle's distances  */
      107.   float getx() {
      108.     return x;
      109.   }
      110.   float gety() {
      111.     return y;
      112.   }
      113.   void update(int num) {
      114.    /* Friction is simulated here */
      115.    vx *= 0.84;
      116.    vy *= 0.84;
      117.    /* Here, every particle is looped through and checked to see if they're close enough to have effect on the current particle. */
      118.    for (int i = particleCount; i >= 0; i--)  {
      119.      /* Check to see if the particle we're checking isn't the current particle. */
      120.      if (i != num) {
      121.         /* drawthis boolean is initialized. it determines whether the particle is close enough to the other particles for relationship lines to be drawn, assuming it's enabled */
      122.         boolean drawthis = false;
      123.         /*
      124.         Integers are used to keep track of the shade for each particle
      125.         The red shade shows opposition
      126.         The blue shade shows attraction
      127.         */
      128.         float redshade = 20;
      129.         float blueshade = 500;
      130.         /* We set our particle */
      131.         Particle particle = (Particle) particles[i];
      132.         /* The x and y coordinates of the particle is found, so we can compare distances with our current particle. */
      133.         float tx = particle.getx();
      134.         float ty = particle.gety();
      135.         /* The radius or distance between both particles are determined */
      136.         float radius = dist(x,y,tx,ty);
      137.         /* Is the radius small enough for the particle to have an effect on our current one? */
      138.         if (radius < 35) {
      139.            /* We've the determine that the particle is close enough for relationship lines, so we set drawthis to true. */
      140.            drawthis = true;
      141.            /* If so, we proceed to calculate the angle. */
      142.            float angle = atan2(y-ty,x-tx);
      143.            /* Is the radius close enough to be deflected? */
      144.            if (radius < 30) {
      145.              /* Is relationship lines toggled? */
      146.              if (lines) {
      147.                /*
      148.                Redshade is increased by the distance * 5. The distance is multiplied by 10 because our radius will be within 40 pixels,
      149.                30 * 13.33... is 400
      150.                We invert it so it gets redder as the particle approaches the current particle, rather than vice versa.
      151.                */
      152.                redshade = 13 * (30 - radius);
      153.              }
      154.              /*
      155.              Here, we calculate a coordinate at a angle opposite of the direction where the other particle is.
      156.              0.07 is the strength of the particle's opposition, while (40 - radius) is how much it is effected, according to how close it is.
      157.              */
      158.              vx += (30 - radius) * 0.07 * cos(angle);
      159.              vy += (30 - radius) * 0.07 * sin(angle);
      160.            }
      161.            /*
      162.            Here we see if the particle is within 25 and 35 pixels of the current particle
      163.            (we already know that the particle is under 35 pixels distance, since this if statement is nested
      164.            in if (radius < 35), so rechecking is unnecessary
      165.            */
      166.            if (radius > 25) {
      167.              /* check to see if relationship lines are toggled */
      168.              if (lines) {
      169.                /* The blue shade, between 0 and 400, is used to show how much each particle is attracted */
      170.                blueshade = 40 * (35 - radius);
      171.              }
      172.              /* This does the opposite of the other check. It pulls the particle towards the other.  */
      173.              vx -= (25 - radius) * 0.005 * cos(angle);
      174.              vy -= (25 - radius) * 0.005 * sin(angle);
      175.            }
      176.         }
      177.         /* Check to see if relationship lines are enabled */
      178.         if (lines) {
      179.           /* Check to see if the two particles are close enough. */
      180.           if (drawthis) {
      181.              /* Set the stroke color */
      182.              stroke (redshade, 10, blueshade);
      183.              /* draw the line */
      184.              line(x,y,tx,ty);
      185.           }
      186.         }
      187.       }
      188.     }
      189.     
      190.     /* Check to see if the user is clicking */
      191.     if (mousePressed) {
      192.       /* The cursor's x and y coordinates. */
      193.       float tx = mx;
      194.       float ty = my;
      195.       /* the distance between the cursor and particle */
      196.       float radius = dist(x,y,tx,ty);
      197.       if (radius < 100) {
      198.         /* Calculate the angle between the particle and the cursor. */
      199.         float angle = atan2(ty-y,tx-x);
      200.         /* Are we left-clicking or not? */
      201.         if (mouseButton == LEFT) {
      202.           /* If left, then the particles are deflected */
      203.           vx -= radius * 0.07 * cos(angle);
      204.           vy -= radius * 0.07 * sin(angle);
      205.           /* The stroke color is red */
      206.           stroke(radius * 4,0,0);
      207.         }
      208.         else {
      209.           /* If right, the particles are attracted. */
      210.           vx += radius * 0.07 * cos(angle);
      211.           vy += radius * 0.07 * sin(angle);
      212.           /* The stroke color is blue */
      213.           stroke(0,0,radius * 4);
      214.         }
      215.         /* If line relationships are enabled, the lines are drawn. */
      216.         if (lines) line (x,y,tx,ty);
      217.       }
      218.     }  
      219.     /* Previox x and y coordinates are set, for drawing the trail */
      220.     int px = (int)x;
      221.     int py = (int)y;
      222.     /* Our particle's coordinates are updated. */
      223.     x += vx;
      224.     y += vy;
      225.     /* Gravity is applied. */
      226.     if (gravity == true) vy += 2;
      227.     /* Border collisions */
      228.     if (x > width-11) {
      229.       /* Reverse the velocity if towards wall */
      230.       if (abs(vx) == vx) vx *= -1.0;
      231.       /* The particle is placed back at the wall */
      232.       x = width-11;
      233.     }
      234.     if (x < 11) {
      235.       if (abs(vx) != vx) vx *= -1.0;
      236.       x = 11;
      237.     }
      238.     if (y < 11) {
      239.       if (abs(vy) != vy) vy *= -1.0;
      240.       y = 11;
      241.     }
      242.     if (y > height-11) {
      243.       if (abs(vy) == vy) vy *= -1.0;
      244.       vx *= 0.6;
      245.       y = height-11;
      246.     }
      247.     /* if relationship lines are disabled */
      248.     if (!lines) {
      249.       /* The stroke color is set to white */
      250.       stroke (400);
      251.       /* The particle is drawn */
      252.       line(px,py,int(x),int(y));
      253.     }
      254.   }
      255. /* User presses a key */
      256. void keyPressed() {
      257.   /* if they press g */
      258.   if (key == 'g' || key == 'G') {
      259.     /* we toggle gravity */
      260.     if (gravity) gravity = false;
      261.     else gravity = true;
      262.   }
      263.   /* otherwise */
      264.   else {
      265.     /* we toggle line relationships */
      266.     if (lines) lines = false;
      267.     else lines = true;
      268.   }
      269.   
      270. }
      Many Thanks
      Miles