Last active
September 6, 2015 06:21
-
-
Save andikan/5cd0c2376d927d5e6f55 to your computer and use it in GitHub Desktop.
Ball.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ball { | |
float x; | |
float y; | |
int size; | |
PVector v; | |
color c; | |
Ball(float x, float y, int size) { | |
this.x = x; | |
this.y = y; | |
this.size = size; | |
this.v = new PVector(); | |
} | |
void draw() { | |
pushStyle(); | |
fill(c); | |
ellipse(x, y, size, size); | |
popStyle(); | |
} | |
void update() { | |
if(millis() % 1 == 0) { | |
this.x = x + v.x; | |
this.y = y + v.y; | |
// println(v); | |
if(x > 1366 || x < 0) { | |
v = new PVector(-v.x, v.y); | |
} | |
if(y > 768 || y < 0) { | |
v = new PVector(v.x, -v.y); | |
} | |
} | |
} | |
void setColor(color c) { | |
this.c = c; | |
} | |
void setV(PVector v) { | |
this.v = v; | |
} | |
void stop() { | |
this.v = new PVector(0, 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setup() { | |
ball1 = new Ball(60, 60, 50); | |
ball2 = new Ball(1300, 700, 50); | |
} | |
draw() { | |
ball1.update(); | |
ball1.draw(); | |
} | |
// set speed | |
ball1.setV(new PVector(0, 5)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment