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”.
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)
Random class to initialize the data membersParticle class. You will need the following members:
Random class. It should be static.
Color randomColor(), randomly chooses one of the 13 basic colors and returns it.
Particle(), the class constructor
void move(), Takes the cos of the angle times the speed
and adds it to the X coordinate. Does the same to Y with the sin of the angle.
void draw(Graphics g), sets the current color to the color of the particle
and draws a dot using fillOval()
Random class 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
*/
I don't know what this is, but it's kind of cool.
Try moving the mouse over the screen.