SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
見出し画像

Let's Draw Fractal Figures! - Programming with Turtle

Beautiful fractal figures that science-minded people can appreciate. The way the same repeating patterns become increasingly finer, creating a sense of infinite continuation, is indescribable. I asked ChatGPT to explain how to draw fractal figures using turtle graphics.


Using turtle graphics, which is also useful for programming education, I will introduce how to draw a fractal figure called a "binary tree." Since the content is easy for programming beginners to enjoy, it is perfect for those who have just started programming or those who want to learn visually. Please try it out with me!

What is a fractal figure?

A fractal figure is a shape where the same form as the whole appears repeatedly. It is often seen in the natural world, with tree branches, river flows, and snowflakes being prime examples. It is characterized by how a large shape branches out into finer and finer details.

What is a binary tree?

The fractal figure we will draw this time is a "binary tree." A binary tree is a tree-like fractal figure with a structure where one branch always splits into two. A binary tree fractal starts from one large branch, which then splits left and right, with finer branches appearing one after another. This "repetition of branching" is the hallmark of fractal figures, creating unique and beautiful patterns.

Let's draw a binary tree with turtle graphics

We will program the flow where a turtle draws a branch on the screen, and that branch further splits into two. Turtle graphics is a tool also used as teaching material for programming education, and its appeal lies in how even programming beginners can learn visually.
https://turtle360.net/jp/

Fractal Figure - Binary Tree -
  • Move forward A: The turtle moves forward by A steps.

  • Turn right 25 degrees: The turtle rotates 25 degrees to the right to draw the next branch.

  • Use module 1: Call the same module again to draw a smaller branch. A decreases by 10 each time.

  • Turn left 50 degrees: Rotate 50 degrees to the left to draw the opposite branch.

  • Go back A: The turtle returns to its original position.

By repeating this movement, one branch splits into two, and those two branches split into two more... and this structure continues, completing the binary tree fractal. The charm of fractal figures lies in this "self-similarity" (the repetition of the same pattern).

Let's modify the program!

This program uses "recursive processing." Recursive processing is a programming mechanism that repeats the same instructions and is one of the important concepts in learning programming. While recursive processing is university-level content, the appeal of using turtle graphics is that even beginners can easily experience how it works.

Changing the size of the tree

The red arrow in the program image indicates the value of variable "A." This value is an important parameter that determines the length of the tree branches. It is set to 80 by default, but you can adjust the size of the tree by changing this value.

Changing the tilt of the tree

If you change one of the two "use module 1" command expressions from "A-10" to something like "A-9", the tree will tilt to the left or right. Try out various numbers and create binary trees in all sorts of shapes.

Simple Programming

The greatest appeal of turtle graphics is that you can enjoy even complex programs in a simple way. Just by slightly modifying the program and changing the numbers, new fractal shapes are born. Since even programming beginners can immediately feel a sense of accomplishment, please give it a try and create your very own binary tree fractal!


いいなと思ったら応援しよう!