Difference between revisions of "FSOSS 2010/processing.js/example6"
Line 5: | Line 5: | ||
Example of line, ArrayList, mousePressed, mouseReleased | Example of line, ArrayList, mousePressed, mouseReleased | ||
*/ | */ | ||
− | + | ||
boolean drawingLine = false; | boolean drawingLine = false; | ||
− | + | ||
float lineX; | float lineX; | ||
float lineY; | float lineY; | ||
− | + | ||
ArrayList lineCoords; | ArrayList lineCoords; | ||
− | + | ||
void setup(){ | void setup(){ | ||
size(300, 300); | size(300, 300); | ||
lineCoords = new ArrayList(); | lineCoords = new ArrayList(); | ||
} | } | ||
− | + | ||
void draw(){ | void draw(){ | ||
background(33, 66, 99); | background(33, 66, 99); | ||
Line 32: | Line 32: | ||
} | } | ||
} | } | ||
− | + | ||
/* | /* | ||
Function gets called once, as soon as the | Function gets called once, as soon as the | ||
Line 42: | Line 42: | ||
lineY = (float) mouseY; | lineY = (float) mouseY; | ||
} | } | ||
− | + | ||
/* | /* | ||
Function gets called once, as soon as the | Function gets called once, as soon as the | ||
Line 54: | Line 54: | ||
lineCoords.add((float) mouseX); | lineCoords.add((float) mouseX); | ||
lineCoords.add((float) mouseY); | lineCoords.add((float) mouseY); | ||
+ | println("Coords: (" + (int)lineX + ", " + (int)lineY + ", " + mouseX + ", " + mouseY + ")"); | ||
} | } | ||
</source> | </source> | ||
[http://studio.sketchpad.cc/???? Run me] | [http://studio.sketchpad.cc/???? Run me] |
Revision as of 10:26, 26 October 2010
/*
FSOSS 2010
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("Coords: (" + (int)lineX + ", " + (int)lineY + ", " + mouseX + ", " + mouseY + ")");
}