Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args)
- {
- Draw.window(601,600);
- Draw.setTitle("Bouncing Ball");
- Draw.setFill(true);
- int x = 0;
- int y = 0;
- int xDirection = 1;
- int yDirection = 1;
- while(true)
- {
- Draw.setColor(0,0,0);
- Draw.oval(x,y,50,50);
- Util.pause(.005);
- Draw.setColor(255,255,255);
- Draw.oval(x,y,50,50);
- x = x + xDirection;
- if (x>550)
- {
- xDirection = Util.random(2,5);
- xDirection = xDirection*-1;
- }
- if (x<0)
- xDirection = Util.random(2,5);
- y = y + yDirection;
- if (y>550)
- {
- yDirection = Util.random(2,5);
- yDirection = yDirection*-1;
- }
- if (y<0)
- yDirection = Util.random(2,5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement