Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Kshatriya Vidhya Sala English Medium School

Virudhunagar

A PROJECT REPORT ON

DRAWING A FRACTAL USING


PYTHON
SUBMITTED BY
Sanjay. S
XI-S
2023-2024
UNDER THE GUIDANCE OF
Mrs J. Reethrose, M.E(CSE)., B.Ed.,
P.G.T in Computer Science
Kshatriya Vidhya Sala English Medium School,
Virudhunagar

ACKNOWLEDGEMENT

Presentation, Inspiration and Motivation has always played a key role in


success of any venture.
I am ineffably indebted to our Principal Mr. P. Rajasekaran, M.Sc., B.Ed.,
M.Phil., for conscientious guidance and encouragement to accomplish this
assignment.
I am extremely thankful and pay my gratitude to my faculty
Mrs J. Reethrose, M.E(CSE)., B.Ed., for her valuable guidance and support on
completion of this project in its presently.
I extend my gratitude to Kshatriya Vidhya Sala English Medium School for
giving me this opportunity.
I also acknowledge with a deep sense of reverence, my gratitude towards
my Parents and members of my family, who has always supported me morally as
well as economically.
On the very outset of this report, gratitude goes to all my friends who
directly or indirectly helped me to complete this project report.
At last but not least, I would like to extend my sincere and heartfelt
obligation towards all the personages who have directly or indirectly helped me in
this endeavour.

Thanking you
Kshatriya Vidhya Sala English Medium School,
Virudhunagar

DECLARATION

I hereby declare that the project entitled “DRAWING A FRACTAL

USING PYTHON” is a record of original project work done by me for the AISSCE

COMPUTER SCIENCE PRACTICAL EXAMINATION (2023 - 2024) under the

supervision and the guidance of Mrs J. Reethrose, M.E(CSE)., B.Ed., P.G. Teacher

in Computer Science, Kshatriya Vidhya Sala English Medium School,

Virudhunagar.

[SANJAY.S]
Kshatriya Vidhya Sala English Medium School,
Virudhunagar

CERTIFICATE

This is to certify that the project entitled “Drawing a Fractal using

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

Medium School, Virudhunagar. The report is found worthy of acceptance as Final

project for the AISSCE Computer Science Practical Examination (2023-2024).

DATE: Teacher’s signature


Drawing a Fractal using Python

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.

The Koch snowflake can be built up iteratively, in a sequence of stages. The


first stage is an equilateral triangle, and each successive stage is formed by adding outward
bends to each side of the previous stage, making smaller equilateral triangles. The areas
enclosed by the successive stages in the construction of the snowflake converge
to 1.6 times the area of the original triangle, while the perimeters of the successive stages
increase without bound. Consequently, the snowflake encloses a finite area, but has
an infinite perimeter.

The Koch snowflake has been constructed as an example of a continuous curve


where drawing a tangent line to any point is impossible. Unlike the earlier Weierstrass
function where the proof was purely analytical, the Koch snowflake was created to be
possible to geometrically represent at the time, so that this property could also be seen
through "naive intuition".
Program
• Program window
• Program in text

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

When depth = 2 When depth = 5


When depth = 7

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

You might also like