Question

with turtle in python: Fractals are fun at every level. (Draw the Koch snowflake) The Koch...

with turtle in python: Fractals are fun at every level. (Draw the Koch snowflake) The Koch snowflake is one of the earliest fractals to have been described. The snowflake has a finite area bounded by an infinitely long line. It can be constructed as follows, starting with an equilateral triangle and doing the following for each side: 1. divide the line segment into three segments of equal length. 2. draw an equilateral triangle pointing outward that has the middle segment from step 1 as its base. remove the line segment that is the base of the triangle from step 2. The recipe for a level n Koch Snowflake: {this is a comment} {draw a triangle with fancy sides} do 3 times: do f(n) turn left 120 degrees f(n): {draw a fancy side} if n = 0: drive forward 1 unit else: {draw _/\_ (from right to left}} do f(n-1) turn right 60 degrees do f(n-1) turn left 120 degrees do f(n-1) turn right 60 degrees do f(n-1)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hii, I have done this exact same question using a slightly bit different approach before. Using a recursive method to draw a fractal line of given number of levels, and repeat it 3 times with varying angle. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

import turtle

#recursive method to draw a fractal line with given distance, angle and levels
def drawFractalLine(distance,angle,level):
    #checking if level is 0 (base condition)
   
if level==0:
        #turning left angle degrees
       
turtle.left(angle)
        #moving turtle in distance
       
turtle.forward(distance)
        #turning right to get back to original direction
       
turtle.right(angle)
        return #end of recursive calls
    #drawing a line 1/3 rd of the total distance in same direction, with one less level
   
drawFractalLine(distance/3,angle,level-1)
    # drawing a line 1/3 rd of the total distance in direction +60 degrees,
    # with one less level
   
drawFractalLine(distance / 3, angle + 60, level - 1)
    # drawing a line 1/3 rd of the total distance in direction -60 degrees,
    # with one less level
   
drawFractalLine(distance / 3, angle - 60, level - 1)
    # drawing a line 1/3 rd of the total distance in same direction, with one less level
   
drawFractalLine(distance / 3, angle, level - 1)


#method to draw a koch snowflake of given width and levels
def drawKochSnowflake(width,levels):
    #drawing first fractal line
   
drawFractalLine(width, 0, levels)
    # drawing second fractal line
   
drawFractalLine(width, -120, levels)
    # drawing third fractal line
   
drawFractalLine(width, 120, levels)


def main():

    #maximum speed for drawing
   
turtle.speed(0)
    #drawing a snowflake with 200 width and levels = 3
   
drawKochSnowflake(200,3)
    #hiding turtle after drawing
   
turtle.ht()
    #finishing drawing
   
turtle.done()

main()

#output


Add a comment
Know the answer?
Add Answer to:
with turtle in python: Fractals are fun at every level. (Draw the Koch snowflake) The Koch...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The Koch snowflake is a fractal shape. At level 0, the shape is an equilateral triangle....

    The Koch snowflake is a fractal shape. At level 0, the shape is an equilateral triangle. At level 1, each line segment is split into four equal parts, producing an equilateral bump in the middle of each segment. Figure 7-15 shows these shapes at levels 0, 1, and 2. Figure 7-15 First three levels of a Koch snowflake Figure 7-15 First three levels of a Koch snowflake At the top level, the script uses a function drawFractalLine to draw three...

  • Part II - Snowflake Island 0r The fractal called snowflake island (or Koch's snowflake) is constructed as fol...

    Part II - Snowflake Island 0r The fractal called snowflake island (or Koch's snowflake) is constructed as follows be You will make foam versions of each iteration you create. It will help iteration as a pattern for you to cut out of the foam. Step 1: Begin with cutting out an equilateral triangle. to make paper versions of each rever you see a straight line, draw an equilateral triangle on the middle third of the line segment and erase its...

  • Part II - Snowflake Island 0r The fractal called snowflake island (or Koch's snowflake) is constructed as follo...

    Part II - Snowflake Island 0r The fractal called snowflake island (or Koch's snowflake) is constructed as follows be You will make foam versions of each iteration you create. It will help iteration as a pattern for you to cut out of the foam. Step 1: Begin with cutting out an equilateral triangle. to make paper versions of each rever you see a straight line, draw an equilateral triangle on the middle third of the line segment and erase its...

  • This is what I am supposed to do: I think he wants us to do this in Java. Thank you! Fractals (a)...

    This is what I am supposed to do: I think he wants us to do this in Java. Thank you! Fractals (a) Write a function in Racket to create a Koch curve fractal. The Koch curve can be constructed by starting with a line (segment), then recursively altering each line segment as follows: divide the line segment into three segments of equal length. draw an equilateral triangle that has the middle segment from step 1 as its base and points...

  • Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a ...

    Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a triangle at depth k given the bottom vertex.    vertex: a tuple (x,y) that gives the coordinates of the bottom vertex. When k=0, vertex is the left bottom vertex for the outside triangle. length: the length of the original outside triangle (the biggest one). k: the depth of the input triangle. As k increases by 1, the triangles shrink to a smaller size. When k=0, the...

  • Hi, can you help me add these requirements in my Turtle python program. The program is...

    Hi, can you help me add these requirements in my Turtle python program. The program is supposed to run an Olympics skating game. The program is below the requirements. Thanks Requirements -Your race will be random generated so each time there is a possibility that a different winner. -Have a countdown of “READY” “SET” “GO” appear on the screen and then the turtles take off. -Have the program tell the winner[s]. -Award Medals. -User may guess who will win. -Allow...

  • Write a program called draw_shapes.py. In your program, Create a block header with: your name the...

    Write a program called draw_shapes.py. In your program, Create a block header with: your name the date a short description of what the program does: Assignment 5: Draw shapes using turtle Import the turtle module. Create a window and screen (canvas) where your turtle will draw. Make the window 400 pixels wide x 400 pixels high and give it an indigo background and a title of "Shapes". Use this code to create a window object: # a place for the...

  • if some can help me one answer of each segment that would be legendary, yall can...

    if some can help me one answer of each segment that would be legendary, yall can answers the easist ones, Choose one of the following to explain, attaching a diagram to help illustrate your answer. Your peers will not be able to see your videos 1. What is the difference between the sine of an angle and the cosine of an angle? Use a triangle diagram to illustrate. 2. What is the difference between tangent and inverse tangent? Use a...

  • Suppose a certain baseball diamond is a square 60 feet on a side. The pitching rubber is located 40.5 feet from home plate on a line joining home plate and second base. (a) How far is it from t...

    Suppose a certain baseball diamond is a square 60 feet on a side. The pitching rubber is located 40.5 feet from home plate on a line joining home plate and second base. (a) How far is it from the pitching rubber to first base? (b) How far is it from the pitching rubber to second base? (c) If a pitcher faces home plate, through what angle does he need to turn to face first base? (a) The distance from the...

  • Consider 1-2 Vr? + y + 3 LLL da dydar. V1-38-98 V +y + y2 +22...

    Consider 1-2 Vr? + y + 3 LLL da dydar. V1-38-98 V +y + y2 +22 +y +22-2 the origin to the point (2, y, ) makes with the z-axis is a new angle which we will label o, and we label the length of the line segment p. We can now determine the remaining side-lengths of our new triangle. Let us try to label our point (2, y, z) in only p and 6. Our labeled triangle gives us...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT