Difference between revisions of "FSOSS 2010/processing.js/example6"
Line 3: | Line 3: | ||
/* | /* | ||
FSOSS 2010 | FSOSS 2010 | ||
+ | Andor Salga | ||
Example of line, ArrayList, mousePressed, mouseReleased | Example of line, ArrayList, mousePressed, mouseReleased | ||
*/ | */ |
Latest revision as of 11:20, 26 October 2010
/*
FSOSS 2010
Andor Salga
Example of line, ArrayList, mousePressed, mouseReleased
*/
boolean drawingLine = false;
float lineX;
float lineY;
ArrayList lineCoords;
void setup(){
size(300, 300);
lineCoords = new ArrayList();
}
void draw(){
background(33, 66, 99);
for(int i = 0; i < lineCoords.size(); i += 4){
line( (Float)lineCoords.get(i),
(Float)lineCoords.get(i+1),
(Float)lineCoords.get(i+2),
(Float)lineCoords.get(i+3));
}
if(drawingLine){
line(lineX, lineY, mouseX, mouseY);
}
}
/*
Function gets called once, as soon as the
mouse button is pressed.
*/
void mousePressed(){
drawingLine = true;
lineX = (float) mouseX;
lineY = (float) mouseY;
}
/*
Function gets called once, as soon as the
mouse button is released.
*/
void mouseReleased(){
drawingLine = false;
lineCoords.add(lineX);
lineCoords.add(lineY);
lineCoords.add((float) mouseX);
lineCoords.add((float) mouseY);
println(lineX + " " + lineY + " " + mouseX + " " + mouseY);
}