Drawing Koch Snowflake Using Python
Drawing Koch Snowflake Using Python
Virudhunagar
A PROJECT REPORT ON
ACKNOWLEDGEMENT
Thanking you
Kshatriya Vidhya Sala English Medium School,
Virudhunagar
DECLARATION
USING PYTHON” is a record of original project work done by me for the AISSCE
supervision and the guidance of Mrs J. Reethrose, M.E(CSE)., B.Ed., P.G. Teacher
Virudhunagar.
[SANJAY.S]
Kshatriya Vidhya Sala English Medium School,
Virudhunagar
CERTIFICATE
Python“ is a record of original project work done by SANJAY.S, of class XI-S, under
the guidance of Mrs J. Reethrose, M.E(CSE)., B.Ed., Kshatriya Vidhya Sala English
Contents
Acknowledgement
Declaration
Certificate
Introduction
Requirements
Koch Snowflake
Program
• Program Window
• Text Program
Output
Conclusion
Bibliography
DRAWING A FRACTAL USING PYTHON
Introduction
When looking around nature, we might have noticed intricate plants like these:
Initially, these appear like highly complex shapes – but when we look closer, we might
notice that they both follow a relatively simple pattern, all the individual parts of the plants
look exactly the same as the entire plant, just smaller. The same pattern is repeated over
and over again, at smaller scales. In mathematics, we call this property self-similarity, and
shapes that have it are called fractals.
A fractal is a geometric shape that has a fractional dimension. Many famous fractals
are self-similar, which means that they consist of smaller copies of themselves. Fractals
contain patterns at every level of magnification, and they can be created by replacing a
procedure or iterating an equation infinitely many times. They are some of the most
beautiful and most bizarre objects in all of mathematics. To create our own fractals, we
have to start with a simple pattern and then repeat it over and over again, at smaller scales.
In this project report we would construct a program about drawing KOCH SNOWFLAKE
using Python with different levels of dissection.
Requirements
• Python version 3 or above
• Turtle module
Koch Snowflake
The Koch snowflake (also known as the Koch curve, Koch star, or Koch Island)
is a fractal curve and one of the earliest fractals to have been described. It is based on the
Koch curve, which appeared in a 1904 paper titled "On a Continuous Curve Without
Tangents, Constructible from Elementary Geometry" by the Swedish mathematician Helge
von Koch.
import turtle
ANGLE = [60,-120,60,0] #These angles are required to draw equilateral triangles.
def get_input_depth():
message = "Please provide the depth of dissection : "
string_as_values = input(message)
while not string_as_values.isnumeric() :
print("The depth must be a positive integer. Try again")
string_as_values = input(message)
return int(string_as_values)
def setup_screen(title,background="white",screen_size_x=640,screen_size_y=320,
tracer_size=800):
print("Setting up Screen")
turtle.title(title)
turtle.setup(screen_size_x,screen_size_y)
turtle.hideturtle()
turtle.penup()
turtle.tracer(tracer_size)
turtle.bgcolor(background)
def draw_koch(size,depth):
if depth > 0 :
for angle in ANGLE :
draw_koch(size/3,depth-1)
turtle.left(angle)
else:
turtle.forward(size)
depth=get_input_depth()
size=500
setup_screen("Koch Snowflake" ,background="black", screen_size_x=1000,
screen_size_y=600)
turtle.color("sky blue")
turtle.penup()
turtle.setposition(-300,0)
turtle.left(30)
turtle.pendown()
for _ in range(3):
draw_koch(size,depth)
turtle.right(120)
turtle.update()
turtle.done()
print("Done")
Output
By the use of the above code the following output has been obtained
When depth = 0 When depth = 1
Conclusion
With the help of the above code the program is created successfully and the output
is matching with the expected output of Koch Snowflake. Hence program to draw Koch
Snowflake is successfully created using Python.
Bibliography
• mathingon.org
• Advanced Guide to Python 3 programming by John Hunt