SE 450 Homework Assignment #3: Animated Applet

This animated applet, FallingStar, contains 2 animated shapes. The first is a 3DRectangle. The color is randomized and changes in every frame. The Rectangle moves in a linear fashion, similar to the bouncing ball, although the constants defining the path have been changed. In addition, the width and height of the rectangle are randomly chosen at the initiation of the applet and the size of the rectangle changes over time. The rectangle switches between growth and contraction every time a wall is hit or a minimum or maximum size (25% of the applet box dimension) for width or height is met.

The second component of the applet is a 5-pointed star rendered as a polygon object. The color of the star is randomized and is the same as the 3DRectangle. The "falling star" starts at the top of the applet box and drops to the bottom. When at the bottom, a random location is selected at the top of the box and the star falls again. Unlike the changing rectangle, each falling star is a newly generated object. The positioning of the star is accomplished with the translate method in the polygon class. When the Rectangle object fully contains the star object, the program prints text, halts temporarily and restarts the fall of the star from a random point along the top.

Additional note: I tried to use the Rectangle class method "contains" to determine whether the star was in the box. However, while it would work in the appletviewer, it would not work in either a NS 4.7 or IE 5.0 browser window. Thus, in the applet shown here I substituted my own comparison code instead of the "contains" method.

The background on which the graphics are drawn and the speed with which they are drawn are determined in the HTML file using parameters in the applet tag. There are three paramters supplied as integers. The text color is the "inverse" of the color supplied in the parameter tag as determined by subtracting the color value from 255.

 


Source code for Animated Applet: FallingStar.java

Return: Home or to SE450 Main Page