Sitemap

Dragon Curve: Beauty of Mathematics

Introduction and implementation in Python

--

What is the Dragon Curve?

Let’s take a paper strip. Now fold it from the middle. We get a V shape. again fold it from the middle. We get something like a question mark symbol. Let’s fold it one more time. One more time. What we get is these kinds of designs.

Press enter or click to view image in full size

When we keep on folding the paper this way. We start getting some interesting designs.

And We keep on folding it till infinite. We get the Dragon Curve. practically it is not possible to fold it infinite times. Here is the shape of paper after 15 folds.

I tried it with 21 folds. Even in 7 hours, it couldn’t render half of the design and It is too big to fit in my computer screen (Incomplete)

Press enter or click to view image in full size

So, this is the Dragon Curve, which contains the beauty of Mathematics in itself. The interesting thing is paper is not crossing itself any time.

Get Shivam Agrawal’s stories in your inbox

Join Medium for free to get updates from this writer.

Dragon Curve replicates itself in each iteration.

Here are the four copies of the Dragon Curve fit together tightly.

Press enter or click to view image in full size

Implementation in Python

Let’s write a Python script. which may draw Dragon Curve with a specified number of folds.

  • For this We’ll use Python graphics library named Turtle. to install it, use this command.
pip install turtle
  • Now create a file named draw.py
  • You can get the code here.

Working of the script

We have created a function fold which is calling itself recursively. it generates an array of zeros and ones. where zero indicates left fold and one indicates right fold. this function is finding the middle of the given array and make one (right fold) there. then it will call itself on both sides of the remaining array. and so on….

Then we have used turtle module to convert this binary array into visual graphics. Turtle draws the curve in front of you.

  • To run the script.
python3 draw.py

Dragon Curve shows us, We are surrounded by beautiful Math secrets, which are waiting to be discovered.

Resources

Hope, You Enjoyed.

--

--