Created
March 12, 2020 05:36
-
-
Save todocono/c776c32a5f44df3abd53a14202c8ccc9 to your computer and use it in GitHub Desktop.
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
/* IxLab 2020S - NYU Shanghai | |
* recorded to introduce concepts | |
* Ideas for exercises to practice: | |
* Add a third ball bouncing | |
* Make the size different for dif. balls | |
* Make the color different for dif. balls | |
*/ | |
float x1, y1; //position of the ball 1 | |
float x2, y2; //position of the ball 2 | |
float spdX1, spdY1; //speed of the ball 1 | |
float spdX2, spdY2; //speed of the ball 2 | |
color c; //color of the ball | |
int d = 20; | |
void setup() { | |
size(400, 400); | |
x1 = random(width); | |
y1 = random(height); | |
x2 = random(width); | |
y2 = random(height); | |
noStroke(); | |
spdX1 = random(-10, 10); | |
spdY1 = random(-10, 10); | |
spdX2 = random(-10, 10); | |
spdY2 = random(-10, 10); | |
} | |
void draw() { | |
background(125); | |
fill(c); | |
ellipse (x1, y1, d, d); | |
ellipse (x2, y2, d, d); | |
x1 = x1 + spdX1; | |
y1 = y1 + spdY1; | |
x2 = x2 + spdX2; | |
y2 = y2 + spdY2; | |
if ((x1 > width-d/2) || (x1 < d/2)) { // x is too big | |
spdX1 *= -1; // spdX = -spdX; | |
} | |
if ((y1 > height-d/2) || (y1 < d/2)) { // x is too big | |
spdY1 *= -1; | |
} | |
if ((x2 > width-d/2) || (x2 < d/2)) { // x is too big | |
spdX2 *= -1; // spdX = -spdX; | |
} | |
if ((y2 > height-d/2) || (y2 < d/2)) { // x is too big | |
spdY2 *= -1; | |
} | |
//if ((x2 > width) || (x2 < 0)) { // x is too big | |
// spdX *= -1; // spdX = -spdX; | |
//} | |
//if ((y2 > height) || (y2 < 0)) { // x is too big | |
// spdY *= -1; | |
//} | |
} | |
void mousePressed() { | |
c = color(random(0, 255), random(0, 255), random(0, 255)); | |
} | |
void keyPressed() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment