Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python 3 Here is the template import turtle def Koch(length, order): ''' order 0 Koch is just a straight line ''' if order ==

In python 3

image text in transcribed

Here is the template

import turtle

def Koch(length, order): ''' order 0 Koch is just a straight line ''' if order == 0: turtle.forward(length) else: ''' TODO: make recursive calls to do the drawing order d Koch is composed of 4 of order (d-1) Koch '''

#test def main(): turtle.setworldcoordinates(-1, -1, 150, 150) turtle.penup() turtle.goto(10,70) turtle.pendown() Koch(120, 3) turtle.mainloop() main()

on Fractals are patterns that are self-similar across different scales. They are created by repeating a simple similar process over and over in a loop. Since the process is repeated often in a smaller and smaller scale, recursion is appropriate to use to create them. You can learn more on fractals on the Wikipedia In this lab exercise you will draw part of the Koch Snowflake, also known as Koch fractal. See Wikipedia page iki/Koch snowfiake to know more about it. The figure on the right illustrates this snowflake. However, we will do just one line of this initial triangle. The Koch function basically transforms a line segment at one level into four line segments at the next level with the four lines forming a peek as follows: Order 0 Koch fractal: a straight line segment Order 1 Koch fractal: Four line segments In general order n Koch fractal is composed of 4 Order (n-1) Koch fractals. An order 3 Koch fractal would look like this: You can see already the recursion. But how will you do this? You can import the Python turtle to do turtle graphics. It is fairly simple. The turtle is this dot on the screen that you can order to move in some directions to trace lines. You can learn more about the turtle here: ocs n.org/3.3/librarv/turtle.html The following functions would be helpful in this lab exercise: turtle.forward(d), turtle.right(angle), turtle.left(angle). Frite the recursive Koch0 function which takes 2 arguments, length and order, and draws the Koch fractal of given order and length. To draw an Order n Koch fractal, we can draw the first Order (n-1) Koch fractal, then turn left by 600 and draw the second piece. After that, make a right tum draw the 3rd piece and finally tun left and draw the last segment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions

Question

2. Always guess when you can eliminate some of the alternatives.

Answered: 1 week ago