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 />

576<br />

void checkOverInitialNode(){<br />

if (isInitialNode()){<br />

initialNode = color(255, 127, 0);<br />

}<br />

else {<br />

initialNode = color(0);<br />

}<br />

}<br />

The checkOverInitialNode() function sets the color variable initialNode to orange<br />

when the mouse hovers over the initial node, <strong>and</strong> then resets it to black when the mouse<br />

moves off the node.<br />

void drawEdge(){<br />

stroke(100, 50, 20);<br />

for (int i=0; i0){<br />

line(nodeXPos[i], nodeYPos[i], nodeXPos[i-1], nodeYPos[i-1]);<br />

}<br />

// close shape, line between last node <strong>and</strong> initial node<br />

if (isShapeClosed && i == nodeXPos.length-1){<br />

line(nodeXPos[i], nodeYPos[i], nodeXPos[0], nodeYPos[0]);<br />

}<br />

}<br />

}<br />

drawEdge() draws a line connecting the plotted nodes. The for loop is controlled by the<br />

length of the nodeXPos[] array, which increases each time a new node is plotted. The conditional<br />

blocks nested within the for loop ensure that lines are drawn only when there are<br />

at least two nodes plotted, <strong>and</strong> that the final line connects the last plotted node with the<br />

initial node, closing the shape.<br />

void drawNode(){<br />

// draw nodes at shape vertices<br />

noStroke();<br />

for (int i=0; i

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

Saved successfully!

Ooh no, something went wrong!