[Python] Drawing a swirl pattern with turtle

This time, I would like to introduce how to draw a spiral pattern (although it is not a curve) in Python.

Turtle graphics

One of the most useful tools for drawing straight lines and curves is "Turtle Graphics". Developed as a teaching material for children, it is designed to be very easy to handle and intuitively understandable.

Python provides a turtle library to handle this turtle graphics as standard.

Source code


import turtle

t = turtle.Turtle()

l = 200    #Initial value of side length
angle = 90 #Angle to change direction after drawing a straight line
step = 10  #Decrease in side length

while l > 10:     #Repeat as long as l is greater than 10
    t.forward(l)  #Go straight only l
    t.left(angle) #Rotate 90 degrees to the left
    l -= step     #Reduce l by 10

When you run this code, you'll get a swirl pattern like this:

bandicam 2020-02-27 21-31-21-411.jpg

Summary

This time, I introduced the code to draw a spiral pattern using turtle graphics.

In addition, you can draw various shapes by using Turtle Graphics. Please try by all means try.

note

Recommended Posts

[Python] Drawing a swirl pattern with turtle
Try drawing a map with python + cartopy 0.18.0
Drawing with Python Tinker
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Make a fortune with Python
Create a directory with python
A sample for drawing points with PIL (Python Imaging Library).
[Python] What is a with statement?
Solve ABC163 A ~ C with Python
Operate a receipt printer with python
A python graphing manual with Matplotlib.
Play with a turtle with turtle graphics (Part 1)
Let's make a GUI with python.
Drawing a silverstone curve using python
Solve ABC166 A ~ D with Python
Learn Python by drawing (turtle graphics)
Create a virtual environment with Python!
I made a fortune with Python.
Building a virtual environment with Python 3
Solve ABC168 A ~ C with Python
Make a recommender system with python
Draw Koch curve with Python Turtle
[Python] Generate a password with Slackbot
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Let's make a graph with python! !!
[Python] Inherit a class with class variables
I made a daemon with Python
[Python] Chapter 03-01 turtle graphics (creating a turtle)
Write a batch script with Python3.5 ~
[Pyenv] Building a python environment with ubuntu 16.04
Create a Python function decorator with Class
Creating a simple PowerPoint file with Python
[Python] A program that creates stairs with #
Let's make a shiritori game with Python
Install Python as a Framework with pyenv
Build a blockchain with Python ① Create a class
Add a Python data source with Redash
Create a dummy image with Python + PIL.
Try drawing a simple animation in Python
I made a character counter with Python
Try drawing a normal distribution with matplotlib
I drew a heatmap with seaborn [Python]
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
I tried drawing a line using turtle
A memo with Python2.7 and Python3 on CentOS
Building a Python 3.6 environment with Windows + PowerShell
Map rent information on a map with python
Search the maze with the python A * algorithm
Daemonize a Python web app with Supervisor
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Created a darts trip with python (news)
I tried a functional language with Python
[Python] A quick web application with Bottle!
[AtCoder] Solve ABC1 ~ 100 A problem with Python
Write a TCP client with Python Twisted
What I did with a Python array
Solve AtCoder ABC168 with python (A ~ D)