AP Java Assignment 5
Starfield


For this assignment you will make a simple animation of fireworks. This common animation is called a “starfield” since it can also be used to simulate movement through a field of stars. You will use a class to represent each “particle”.

    Program requirements:
  1. Your program must use a class that represents "particles". Your class should have at least 5 data members: X and Y positions, Color, Direction and Speed. (Hint use doubles for X, Y, Speed and Angle)
  2. All the particles must be stored in an array.
  3. Your program must use at least one constant (for number of particles).
  4. Your class must have a constructor that uses the Random class to initialize the data members

Steps to completing this assignment

  1. Start with the same "fill in the blank" thread applet that you used in assignment 4
  2. Write a Particle class. You will need the following members:
  3. Now add one Particle to the applet, much like you did with the Ball in assignment 4.
  4. Now modify the applet so you have an array of Particles.

Random class

The Random class has a number of member functions that can be used to generate pseudo-random numbers. Below is an example of an applet that uses the Random class.

import java.util.Random;

public class RandomDemo extends Applet
{
	public void paint(Graphics g)
	{
	   Random numberGen = new Random();

	   //display a random true or false
	   System.out.println(numberGen.nextBoolean());

	   //0 <= random decimal < 1
	   System.out.println(numberGen.nextDouble());

	   //approx -5 < "Gaussian" decimal < approx 5
	   System.out.println(numberGen.nextGaussian());

	   //Integer.MIN_VALUE < Random Integer < Integer.MAX_VALUE
	   System.out.println(numberGen.nextInt());

	   //0 <= Random Integer < 5
	   System.out.println(numberGen.nextInt(5));
	}
}
/* Sample Output
true
0.276452570607834
-0.23039171543178555
762029354
4
*/	

Extensions

Have a fun and be creative. If you have extra time you may want to modify your program and add extra features. Try using both "Gaussian" and "normal" random numbers. Experiment with different arrangements of particles. Scroll down to see three other variations


I don't know what this is, but it's kind of cool.
Try moving the mouse over the screen.


And this one looks like you are traveling in space


Here are some spirals