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.

float friction = .85;<br />

float[]jitter = new float[0];<br />

float[]xSpeed = new float[0];<br />

float[]ySpeed = new float[0];<br />

float[]elasticity = new float[0];<br />

void setup(){<br />

size(400, 600);<br />

frameRate(30);<br />

smooth();<br />

}<br />

void draw(){<br />

// create simple shape trails<br />

fill(255, 36);<br />

rect(0, 0, width, height);<br />

if (nodeXPos.length>1){<br />

// draw line between nodes<br />

drawEdge();<br />

// check if mouse is over original node<br />

checkOverInitialNode();<br />

// animate shape<br />

moveShape();<br />

}<br />

// draw node<br />

drawNode();<br />

}<br />

// change node fill color when mouse is over initial node<br />

void checkOverInitialNode(){<br />

if (isInitialNode()){<br />

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

}<br />

else {<br />

initialNode = color(0);<br />

}<br />

}<br />

//function to draw lines between nodes<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 />

INTERACTIVITY<br />

571<br />

12

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

Saved successfully!

Ooh no, something went wrong!