Difference between revisions of "FSOSS 2010/processing.js/example6"
(Created page with 'category: FSOSS 2010 PJS Examples <source lang="JavaScript"> →FSOSS 2010: boolean drawingLine = false; float lineX1; float lineY1; float lineX2; float lineY2; Array…') |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
/* | /* | ||
FSOSS 2010 | FSOSS 2010 | ||
+ | Andor Salga | ||
+ | Example of line, ArrayList, mousePressed, mouseReleased | ||
*/ | */ | ||
− | + | ||
boolean drawingLine = false; | boolean drawingLine = false; | ||
− | + | ||
− | float | + | float lineX; |
− | float | + | 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 30: | Line 29: | ||
} | } | ||
− | |||
if(drawingLine){ | if(drawingLine){ | ||
− | line( | + | line(lineX, lineY, mouseX, mouseY); |
} | } | ||
} | } | ||
− | + | ||
/* | /* | ||
Function gets called once, as soon as the | Function gets called once, as soon as the | ||
Line 42: | Line 40: | ||
void mousePressed(){ | void mousePressed(){ | ||
drawingLine = true; | drawingLine = true; | ||
− | + | lineX = (float) mouseX; | |
− | + | lineY = (float) mouseY; | |
} | } | ||
− | + | ||
/* | /* | ||
Function gets called once, as soon as the | Function gets called once, as soon as the | ||
Line 53: | Line 51: | ||
drawingLine = false; | drawingLine = false; | ||
− | lineCoords.add( | + | lineCoords.add(lineX); |
− | lineCoords.add( | + | lineCoords.add(lineY); |
lineCoords.add((float) mouseX); | lineCoords.add((float) mouseX); | ||
lineCoords.add((float) mouseY); | lineCoords.add((float) mouseY); | ||
+ | println(lineX + " " + lineY + " " + mouseX + " " + mouseY); | ||
} | } | ||
</source> | </source> | ||
− | [http://studio.sketchpad.cc/ | + | [http://studio.sketchpad.cc/JzipgTGyKN Run me] |
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);
}