Open main menu

CDOT Wiki β

Changes

FSOSS 2010/processing.js/example6

1,058 bytes added, 11:35, 25 October 2010
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…'
[[category: FSOSS 2010 PJS Examples]]
<source lang="JavaScript">
/*
FSOSS 2010
*/

boolean drawingLine = false;

float lineX1;
float lineY1;

float lineX2;
float lineY2;

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(lineX1, lineY1, mouseX, mouseY);
}
}

/*
Function gets called once, as soon as the
mouse button is pressed.
*/
void mousePressed(){
drawingLine = true;
lineX1 = (float) mouseX;
lineY1 = (float) mouseY;
}

/*
Function gets called once, as soon as the
mouse button is released.
*/
void mouseReleased(){
drawingLine = false;

lineCoords.add(lineX1);
lineCoords.add(lineY1);
lineCoords.add((float) mouseX);
lineCoords.add((float) mouseY);
}
</source>

[http://studio.sketchpad.cc/???? Run me]
1
edit