Starting from:
$35

$29

Homework 04 solution

We have already seen in class how to draw a svTree at various recursion levels. In the first part of HW 4, you will be drawing Koch snowflake at a given recursion level.

Note that the snowflake is an inverted triangle with each side growing flake recursively. Each side has the circled pattern at various recursion levels.

First write a recursive function snowflakeSide(level,length) :

For base case, draw a line of given length. For recursion case, recursively call the function 4 times at level one less, one for flat side, one after turning left 60 degrees, another after turning right 120 degrees and another (after turning left how many degrees ?) to be level with first line.

Now write the non-recursive function snowflake(level, length) that calls snowflakeSide 3 times one for each side of a triangle (turning right 120 degrees 3 times)

NOTE: All these functions do not need to have a return statement.

Have fun with flakes!!

More products