In this assignment you will create a class to model a single snowflake. Then you will create an array of many snowflakes. You may find slides 241 - 345 on apjava1.pptx and the Arrays of Objects worksheet helpful.
Steps to completing the program (These are just a suggested starting point. Feel free to adjust them anyway you'd like):
-
Sign in to GitHub and fork this repository
-
Add the following to the
Snowflake
class.
- 2 member integer variables:
x
andy
- 1 member boolean variable:
isMoving
- The constructor should initialize the members as follows:
x
: random integer from 0 to 300 (or whatever the width of the screen is) You must useMath.random()
y
: random integer from 0 to 300 (or whatever the height of the screen is) You must useMath.random()
isMovin
g:true
void erase()
which first, sets the fill to black and draws a black ellipse of size 7 at (x,y)void move()
which checks if the snowflake isMoving. If it is, increasey
by onevoid lookDown()
checks ify
is between the top and bottom of the screen, and the position just below (x,y) is not black. If so, setisMoving
tofalse
; otherwise setisMoving
totrue
void show()
which draws a white ellipse of size 5 at x,yvoid wrap()
which checks if they
coordinate is off the bottom of the screen. If it is, sety
to 0 and generate a new randomx
coordinate
- Now create an array of Snowflakes. In
draw()
write a loop that goes through the array and for each snowflake does the following:
erase()
lookDown()
move()
wrap()
show()
- In
mouseDragged()
write some code that draws to the screen. - When you are happy with your assignment, push your repository to your GitHub account. Submit the url of your working program to the school loop drop box.
Your "snow" doesn't have to fall down. You could have bubbles that travel upward toward a barrier or some other similar objects. You can keep score based on how many snowflakes have been caught. Have fun and be creative!