topical media & game development
graphic-processing-algorithm-Ch06-p140-MyElement.pde / pde
class MyElement{
int diameter = 5;
float xpos = 0.;
float ypos = 0.; //position
float friction = 0.5;
float xspeed = 0;
float yspeed = 0; // speed
void move() {
xpos += (xspeed/friction);
ypos += (yspeed/friction);
if (xpos > width) xspeed *= -1;
else if (xpos < 0) xspeed *= -1;
if (ypos > height) yspeed *= -1;
else if (ypos < 0) yspeed *= -1;
xpos = constrain(xpos, 0, width);
ypos = constrain(ypos, 0, height);
ellipse(int(xpos),int(ypos),diameter,diameter);
friction += 0.01;
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.