Class MovingStars
[ Source
| Index
| Back to Nelzan ]
- class MovingStars
- extends Object
MovingStars - Displays stars that move at random speeds.
This class generates a variable number of stars, puts them at
random locations, with random colors, and moves them at random
speeds.
-
color
-
-
height
-
-
i
-
-
length
-
-
maxXMove
-
-
maxYMove
-
-
r
- For generating random Numbers.
-
width
-
-
x
-
-
xMove
-
-
y
-
-
yMove
-
-
MovingStars(int, int, int, int, int)
- Creates All the data to draw MovingStars.
-
abs(int)
- Returns the distance from zero.
-
genStart()
- Generates the stars starting location, everything is random.
-
paint(Graphics)
- Paints the stars.
-
update()
- Updates the stars location.
x
private int x[]
y
private int y[]
xMove
private int xMove[]
yMove
private int yMove[]
color
private Color color[]
height
private int height
width
private int width
maxXMove
private int maxXMove
maxYMove
private int maxYMove
length
private int length
r
Random r
- For generating random Numbers.
i
int i
MovingStars
MovingStars(int width,
int height,
int maxX,
int maxY,
int count)
- Creates All the data to draw MovingStars.
- Parameters:
- width - The width of the screen.
- height - The height of the screen.
- maxX - Max speed the stars move in the X direction.
- maxY - Max speed the stars move in the Y direction.
- count - The number of stars to display.
update
public void update()
- Updates the stars location. It will also generate a new star should the
current one be outside of visual range.
paint
public void paint(Graphics g)
- Paints the stars.
- Parameters:
- g - Where to draw the stars.
genStart
private void genStart()
- Generates the stars starting location, everything is random.
abs
private int abs(int i)
- Returns the distance from zero.
- Parameters:
- i - The number to check.
- Returns:
- s an
int of the distance from zero.