Difference between revisions of "FSOSS 2010/processing.js/example5"

From CDOT Wiki
Jump to: navigation, search
(Created page with 'category: FSOSS 2010 PJS Examples <source lang="JavaScript"> /* FSOSS 2010 Example of ArrayList and its methods add, remove, get, size http://www.processing.org/referen…')
 
 
Line 3: Line 3:
 
/*
 
/*
 
   FSOSS 2010
 
   FSOSS 2010
 +
  Andor Salga
 
   Example of ArrayList and its methods add, remove, get, size
 
   Example of ArrayList and its methods add, remove, get, size
  http://www.processing.org/reference/ArrayList.html
 
 
*/
 
*/
  
Line 50: Line 50:
 
}
 
}
 
</source>
 
</source>
 +
[http://studio.sketchpad.cc/K5NpbQ0nMG Run me]

Latest revision as of 06:55, 28 October 2010

/*
  FSOSS 2010
  Andor Salga
  Example of ArrayList and its methods add, remove, get, size
*/

ArrayList circles;

void setup(){
  size(500, 500);
  circles = new ArrayList();
 
  // set the fill and stroke colors to blue
  // for the circles once on setup
  stroke(#336699);
  fill(#336699);
}

void draw(){
  // clear the background to white
  background(#FFFFFF);
 
  // ArrayList's size function returns the number
  // of elements in the list
  for(int i = 0; i < circles.size(); i += 2){
    
    float x = (Float)circles.get(i);
    float y = (Float)circles.get(i+1);
    
    ellipse(x, y, 15, 15);
  }
 
  // if the mouse is pressed, add a circle
  if(mousePressed){
    circles.add((float)mouseX);
    circles.add((float)mouseY);  
  }
 
  // if the mouse button isn't down, remove one circle  
  else{
    int size = circles.size();
    if(size > 0){
      // remove the last two numbers
      circles.remove(size-1);
      circles.remove(size-2);
    }
  }
}

Run me