Although I found it easier to write snowbank-creation code than to write snowflake-creation code, I found it harder to design the snowbank than the snowflakes. Snowbank creation is one of Listing 1's tasks. Private double rotateY (double x, double y, double angle) * equivalent y component following rotation * angle number of radians in which to rotate y component * Rotate the y component of a point through a clockwise angle around the Private double rotateX (double x, double y, double angle) * equivalent x component following rotation * angle number of radians in which to rotate x component * Rotate the x component of a point through a clockwise angle around the G.drawLine (centerx+(int) startx, centery+(int) starty,ĭouble cx = startx+(endx-startx)*BRANCH_FACTOR ĭouble cy = starty+(endy-starty)*BRANCH_FACTOR ĭouble nendx = cx+(endx-startx)*SHRINK_FACTOR ĭouble nendy = cy+(endy-starty)*SHRINK_FACTOR ĭouble rx1 = rotateX (nendx-cx, nendy-cy, BRANCH_ANGLE)+cx ĭouble ry1 = rotateY (nendx-cx, nendy-cy, BRANCH_ANGLE)+cy ĭouble rx2 = rotateX (nendx-cx, nendy-cy, -BRANCH_ANGLE)+cx ĭouble ry2 = rotateY (nendx-cx, nendy-cy, -BRANCH_ANGLE)+cy ĭrawSnowflakeBranch (g, cx, cy, rx1, ry1, depth+1) ĭrawSnowflakeBranch (g, cx, cy, rx2, ry2, depth+1) Private void drawSnowflake (Graphics2D g)įor (int branch = 0 branch 1 ? 1 : 2)) * g graphics device on which branch and sub-branches are painted Furthermore, each branch is raised 30 degrees above the x axis. Each branch is positioned 60 degrees from the previous * Draw the snowflake in terms of its six branches, and their three levels X = (int) (Math.random ()*(awidth-2*radius)) * stopping the music, and an image buffer is created for painting each * datastructure, a mouse listener is registered for playing and SnowFlake objects are created and placed into a * Datastructure for managing SnowFlake objects. * Animation thread - created in the start() method and destroyed in the "And, my dear, we're still good-bye-ing,", "Let it snow, let it snow, let it snow.", Note: I am not certain if these lyrics match * displayed on what appears to be a glass pane over the middle of the * "Let It Snow! Let It Snow! Let It Snow!" song lyrics. Passed to each SnowFlake object's constructor and also * used to eliminate one source of flicker. * The graphics device associates with an image buffer. * Graphics device on which animation frames are painted. Not very accurate, but convenient for this * "Let It Snow! Let It Snow! Let It Snow!" audio clip. Private final static int MAX_RADIUS = 35 * Number of SnowFlake objects (and, hence, snowflakes) managed by this * method is called every DELAY milliseconds. * Animation loop delay factor (in milliseconds). Public class LetItSnow extends Applet implements Runnable * This class describes the LetItSnow applet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |