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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

496<br />

// stops motion<br />

float damping, friction;<br />

void setup(){<br />

size(400, 400);<br />

x=width/2;<br />

w=20;<br />

h=w;<br />

fill(0);<br />

speedX = 4;<br />

// set dynamics<br />

gravity = .5;<br />

damping = .8;<br />

friction = .9;<br />

}<br />

void draw(){<br />

fill(255, 60);<br />

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

fill(0);<br />

rect(x, y, w, h);<br />

x+=speedX;<br />

speedY+=gravity;<br />

y+=speedY;<br />

// Check display window edge collisions<br />

if (x > width-w){<br />

x = width-w;<br />

speedX*=-1;<br />

}<br />

else if (x < 0){<br />

x = 0;<br />

speedX*=-1;<br />

}<br />

else if (y > height-h){<br />

y = height-h;<br />

speedY*=-1;<br />

speedY*=damping;<br />

speedX*=friction;<br />

}<br />

else if (y < 0){<br />

y = 0;<br />

speedY*=-1;<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!