Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.util.*;
- public class CopyOfPongette {
- public static void main(String[] args) {
- Random r = new Random();
- int width = 150;
- int height = 237;
- DrawingPanel2 panel = new DrawingPanel2(width, height);
- Graphics g = panel.getGraphics();
- panel.setBackground(Color.red);
- int nMoves = 2000;
- int dx = 2;
- int dy = 1;
- Circle c1 = new Circle(40, 40, 25);
- for ( int i = 0; i < nMoves; i++)
- {
- c1.draw(g);
- panel.sleep(25); // pause
- c1.erase(g, Color.white);
- if (c1.hitsVerticalWall(width))
- dx = -dx;
- c1.move(dx, dy);
- g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
- if (c1.hitsHorizontalWall(height))
- dy = -dy;
- c1.move(dx, dy);
- g.setColor(new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)));
- }
- c1.draw(g);
- }
- }
Add Comment
Please, Sign In to add comment