-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBouncingBall.java
More file actions
25 lines (24 loc) · 924 Bytes
/
Copy pathBouncingBall.java
File metadata and controls
25 lines (24 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* *****************************************************************************
* Name: Ada Lovelace
* Coursera User ID: 123456
* Last modified: October 16, 1842
**************************************************************************** */
public class BouncingBall {
public static void main(String[] args) {
double x = 0.000, y = 0.000;
StdDraw.setXscale(-1.0, +1.0);
StdDraw.setYscale(-1.0, +1.0);
double vx = 0.013, vy = 0.021;
while (true) {
StdDraw.setPenColor(StdDraw.LIGHT_GRAY);
StdDraw.filledSquare(0.0, 0.0, 1.0);
if (Math.abs(x + vx) + 0.05 > 1.0) vx = -vx;
if (Math.abs(y + vy) + 0.05 > 1.0) vy = -vy;
x = x + vx;
y = y + vy;
StdDraw.setPenColor(StdDraw.BLACK);
StdDraw.filledCircle(x, y, 0.05);
StdDraw.show(5);
}
}
}