Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python please Fractals are patterns that are self-similar across different scales. They are created by repeating a simple similar process over and over in

image text in transcribed

In Python please

image text in transcribed

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 page: https://en.wikipedia.org/wiki/Fractal In this lab exercise you will draw part of the Koch Snowflake, also known as Koch fractal. See Wikipedia page https://en.wikipedia.org/wiki/Koch snowflake 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: ITI 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 60 and draw the second piece. After that, make a right turn draw the 3rd piece and finally turn left and draw the last segment. import turtle def Koch(length, order): order 0 Koch is just a straight line if order0 else: turtle.forward(length) 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

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

MySQL/PHP Database Applications

Authors: Jay Greenspan, Brad Bulger

1st Edition

978-0764535376

More Books

Students also viewed these Databases questions