Write a separate program that imports the bug class
and uses it to draw the following picture.
This one uses recursion!
Below are examples of six Koch curves that have recursion depths from 0 (a straight line) at the top to 5 at the bottom.
A Koch curve is created by breaking a line segment into thirds and replacing the middle segment by two segments that are equal in length. This creates a two-sided equilateral triangle in the middle (i.e., 60 degree angles).
Notice that each straight line at one depth is replaced at the next higher depth with a smaller line, then the bump (60-degree turn, another line, 120-degree turn the other way, another line, 60-degree turn), and a final line. For example, looking at the depth 3 curve:
The first segment is really just a full depth 2 curve, then we turn 60 degrees, and draw another depth 2 curve, turn 120 the other way, draw another depth 2 curve, and so on. And the first depth 2 segment is a depth 1 curve. So at any given depth, you create each segment by recurring to depth - 1. This continues until we get to depth 0, which is just a straight line.
Start by creating a function called koch:
koch(bug, depth, distance)which draws a line of the given distance (move the bug forward) if the depth is 0. If the depth is greater than zero, your function should recur 4 times to depth-1, with the appropriate turns in between (60 degrees one way, 120 the other way, and another 60 degrees).
The full "snowflake" is made by creating 3 Koch curves as part of an equilateral triangle.