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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

is smaller (vertically) than the entire display window.*/<br />

parentNode[0] = canvasWidth/2;<br />

parentNode[1] = canvasHeight/2;<br />

/*Fill pallete with r<strong>and</strong>om colors for brush shape edges.<br />

Each shape can have between 2 <strong>and</strong> 8 edges*/<br />

setPalette();<br />

// Font for key comm<strong>and</strong>s at bottom of sketch<br />

font = createFont("Verdana", 12);<br />

}<br />

void draw(){<br />

/*xSpeed <strong>and</strong> ySpeed variables controlled by trig functions.<br />

rotation variable is controlled by user, through keystroke<br />

comm<strong>and</strong>s. x <strong>and</strong> y value of parentNode is incremented by<br />

xSpeed <strong>and</strong> ySpeed. The brush shape is drawn around the<br />

parentNode as its origin, ensuring the brush shape moves<br />

with the parentNode*/<br />

xSpeed = cos(radians(rotation))*speed*xDirection;<br />

ySpeed = sin(radians(rotation))*speed*yDirection;<br />

parentNode[0]+=xSpeed;<br />

parentNode[1]+=ySpeed;<br />

/*If isWallSolid boolean variable is true, the shape bounces off<br />

the canvas edges. If false, the shape exits the canvas <strong>and</strong> is<br />

remapped to the opposite side of the canvas. The isWallSolid<br />

variable is controlled by the user with the keystrokes 'b' for<br />

bounce or 'n' for no bounce.*/<br />

if (!isWallSolid){<br />

if (parentNode[0]>canvasWidth+shapeRadius*2){<br />

parentNode[0] = 0;<br />

}<br />

else if (parentNode[0]canvasHeight+shapeRadius*2){<br />

parentNode[1] = 0;<br />

}<br />

else if (parentNode[1]canvasWidth-shapeRadius/2){<br />

xDirection*=-1;<br />

}<br />

else if (parentNode[0]

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

Saved successfully!

Ooh no, something went wrong!