created 01/01/03; revised 06/23/2016

# Chapter 74 Programming Exercises

## Exercise 1

Modify the snowflake method so that different levels of stars are drawn with different colors. Use colors that are all close to pastel blue. Do this by changing the pen color based on the size of the star.

## Exercise 2

Implement the blizzard program: draw a few dozen randomly positioned snowflakes of a few random sizes and a few random colors.

## Exercise 3

Write a program that creates the following figure: Do this by starting with the snowflake program and replacing the method that draws a snowflake with the method

``` drawBoxes( Graphics gr, int x, int y, int width, int height ) ```

that draws a box centered at `(x,y)` of given width and height. If width or height are below a minimum, just draw that box. Otherwise, draw the box and then call the function recursively with a smaller width and height.

You will find the `drawRect( ulX, ulY, width, height)` method of `Graphics` to be useful.

## Exercise 4

Write a program that creates the following figure: The only drawing method this figure uses is `drawLine()`. The basic figure is a triangle. But rather than draw the full sized triangle, draw three small triangles:

• The left vertex of the lower left triangle is the same as the left vertex of the big triangle. Its other two vertices are halfway along the bottom and left sides of the big triangle.
• The right vertex of the lower right triangle is the same as the right vertex of the big triangle. Its other two vertices are halfway along the bottom and right sides of the big triangle.
• The top vertex of the top triangle is the same as the top vertex of the big triangle. Its other two vertices are halfway along the right and left sides of the big triangle.

Write a method

`drawTriangle( Grahics graph, int lowerLeftX, int lowerLeftY, int side )`

that draws a triangle with a lower left corner at `(lowerLeftX, lowerLeftY)` if `side` is small. Otherwise, it draws three triangles with side `side/2` nested inside the big triangle.

You will find it useful to remember that the height of an equilateral triangle is `side*Math.sqrt(3)/2`