04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

612<br />

I mentioned at the beginning of the chapter that <strong>Processing</strong> (with a little help from Java)<br />

allows you to detect multiple mouse clicks. To close the chapter, I’ve included one last simple<br />

example that utilizes multiple mouse clicks on the display window to dynamically<br />

change the number of sides of a polygon. The simple piece of Java code that allows you to<br />

detect multiple mouse clicks is mouseEvent.getClickCount(), which returns an integer<br />

value of the number of clicks. The time delay between clicks determines if the series of<br />

clicks is considered a multiple click input or a series of individual clicks.<br />

// Detecting Multiple Mouse Clicks<br />

int clickCount = 0;<br />

void setup(){<br />

size(400, 400);<br />

smooth();<br />

}<br />

void draw(){<br />

background(255);<br />

translate(width/2, height/2);<br />

rotate(frameCount*PI/180);<br />

drawPoly();<br />

}<br />

void mouseClicked(){<br />

clickCount = mouseEvent.getClickCount();<br />

}<br />

void drawPoly(){<br />

// draw point if single click<br />

if (clickCount==1){<br />

point(0, 0);<br />

}<br />

else {<br />

float ang = 0;<br />

int verts = clickCount;<br />

beginShape();<br />

for (int i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!