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.

Acceleration with Gravity<br />

float speedX, speedY;<br />

float x, y, w, h;<br />

// acceleration force<br />

float gravity;<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 acceleration force<br />

gravity = .5;<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 />

}<br />

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

y = 0;<br />

speedY*=-1;<br />

}<br />

}<br />

MOTION<br />

493<br />

11

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

Saved successfully!

Ooh no, something went wrong!