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.

default constructor<br />

Ball() {<br />

}<br />

Ball(float x, float y, float r) {<br />

this.x = x;<br />

this.y = y;<br />

this.r = r;<br />

}<br />

}<br />

// Vect2D class:<br />

class Vect2D{<br />

float vx, vy;<br />

// default constructor<br />

Vect2D() {<br />

}<br />

Vect2D(float vx, float vy) {<br />

this.vx = vx;<br />

this.vy = vy;<br />

}<br />

}<br />

// checkBoundaryCollision() function:<br />

void checkBoundaryCollision(Ball ball, Vect2D vel){<br />

if (ball.x > width-ball.r){<br />

ball.x = width-ball.r;<br />

vel.vx *= -1;<br />

}<br />

else if (ball.x < ball.r){<br />

ball.x = ball.r;<br />

vel.vx *= -1;<br />

}<br />

else if (ball.y > height-ball.r){<br />

ball.y = height-ball.r;<br />

vel.vy *= -1;<br />

}<br />

else if (ball.y < ball.r){<br />

ball.y = ball.r;<br />

vel.vy *= -1;<br />

}<br />

}<br />

// checkObjectCollision() function:<br />

void checkObjectCollision(Ball[] b, Vect2D[] v){<br />

float d = dist(b[0].x, b[0].y, b[1].x, b[1].y);<br />

if (d < b[0].r + b[1].r){<br />

MOTION<br />

553<br />

11

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

Saved successfully!

Ooh no, something went wrong!