SoFunction
Updated on 2024-10-30

A simple tutorial on using the turtle library in python.

Simple use of python's turtle library

Python's turtle library is a library of intuitive and interesting graph drawing functions, and is one of the standard libraries for python.

I. Plotting coordinate system

The basic framework of the turtle library for drawing graphs: a graph is drawn by the trajectory of a small turtle in a coordinate system, with the initial position of the turtle in the center of the canvas.

(width,height,startx,starty)

,height: the width and height of the main form.

,starty: for the window distance left from the left side of the screen pixel distance and the top of the window from the top of the screen pixel distance.

import turtle
(300,300,300,100)

II. Stroke Control Functions

  • (lift up the brush
  • (lift up the brush
  • (Put down your brushes.)
  • () Setting the brush size
  • () Setting the brush color

III. Shape Drawing Functions

  • (head
  • () Head in the opposite direction of the turtle's current direction.
  • () Brush direction to the left, based on the current brush direction
  • () Brush direction to the right, based on the current brush direction
  • () Change the direction of the brush drawing on the basis of parallel to the X-axis
  • (radius,extent) draws the arc of the extent angle according to the radius radius.
  • () Hide the turtle at the end of the drawing
  • () Empty the palette.
  • () Empty the palette and return the turtle to its initial position.
import turtle
(300,300,300,100)
(3)			# Setting the brush width
('blue')			# Setting the brush color
(20)			# Forward 20 pixels
()			# Lift up the brush
(30)
()			# Put down the brush
(1)			# Setting the brush width
(90)			# Turn 90° left
(50)			#Back 50 pixels
(90)			# Turn 90° to the right
(-50)			# Negative values indicate the opposite direction
(90)			# Turn 90° to the left parallel to the x-axis.
()
(-100)
()
(0)
(30)			'''Draws a circle with a radius of 30 pixels.
Extent not set defaults to drawing a full circle.'''
()

  • turtle.begin_fill
  • turtle.end_fill

Use in pairs to fill in the colors.

import turtle
(300,300)
turtle.begin_fill()
('black')
(50)
turtle.end_fill()
()

summarize

to this article on the python turtle library in the simple use of tutorials on this article, more related to the use of python turtle library content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!