Advertisement
calcpage

LACS03_Ball.java

Jun 1st, 2012
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.73 KB | None | 0 0
  1. //Ball.java MrG 2012.0531
  2. import java.awt.Color;
  3. public class Ball
  4. {
  5.     private double rx;
  6.     private double ry;
  7.     private double vx;
  8.     private double vy;
  9.     private double r;
  10.     private Color c;
  11.  
  12.     public Ball()
  13.     {
  14.         int sign = Math.random()<0.5 ? -1 : 1;
  15.         rx=0.0;
  16.         ry=0.0;
  17.         vx=sign*Math.random()/5;
  18.         vy=sign*Math.random()/5;
  19.         r=Math.random()/2;
  20.         //c=Color.getHSBColor((float)Math.random(),0.8f,0.8f);
  21.         c=new Color((float)Math.random(),(float)Math.random(),(float)Math.random());
  22.     }
  23.  
  24.     public void draw()
  25.     {
  26.         StdDraw.setPenColor(c);
  27.         StdDraw.filledCircle(rx,ry,r);
  28.     }
  29.  
  30.     public void move()
  31.     {
  32.         if(Math.abs(rx+vx)>10){vx=-vx;}
  33.         if(Math.abs(ry+vy)>10){vy=-vy;}
  34.         rx+=vx;
  35.         ry+=vy;
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement