This time, I would like to introduce how to draw a spiral pattern (although it is not a curve) in Python.
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.
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:
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.
Recommended Posts