Open main menu

CDOT Wiki β

Changes

FSOSS 2010/processing.js/example5

1,085 bytes added, 14:58, 25 October 2010
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…'
[[category: FSOSS 2010 PJS Examples]]
<source lang="JavaScript">
/*
FSOSS 2010
Example of ArrayList and its methods add, remove, get, size
http://www.processing.org/reference/ArrayList.html
*/

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);
}
}
}
</source>
1
edit