Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the python turtle drawing command

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "how to use python turtle drawing commands", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use python turtle drawing commands" this article.

Drawing commands

There are many commands for manipulating sea turtles, which can be divided into three types: brush motion commands, brush control commands, and global control commands.

1. The brush movement command command states that turtle.forward (distance) moves distance pixel length turtle.backward (distance) in the current brush direction. Distance pixel length turtle.right (degree) moves clockwise. Left (degree) moves counterclockwise when drawing graphics are moved. When the parameter is missing, it is also necessary to move the brush to the position turtle.penuo () where the coordinate is (xMagney). Turtle.penuo () picks up the brush and does not draw the graph. It is used to draw turtle.circle () circle from another place with a positive (negative) radius. Indicates that the center is on the left (right) of the brush to draw a circle setx () moves the current x-axis to the specified position sety () moves the current y-axis to the specified position setheading (angle) sets the current orientation to angle angle home () sets the current brush position as the origin, facing east °2, the brush control command states that turtle.fillcolor (colorstring) draws the graphics fill color turtle.color (color1, color2) and sets pencolor = color1 Fillcolor = color2turtle.filling () returns whether the current filling state turtle.begin_fill () is ready to start filling the drawing turtle.end_fill () fills the turtle shape of the hidden brush turtle.showturtle () displays the turtle shape of the brush 3, the global control command states that turtle.clear () clears the turtle window, but the position and state of the turtle will not change turtle.reset () empty the window Reset turtle state to start state turtle.undo () undo the last turtle action turtle.isvisible () returns whether the current turtle is visible stamp () copy the current graphic turtle.write (s [, font = ("font_name", font_size, "font_type")]) write text, s is the text content, font is the font parameter, respectively is the font name, font size and type, the parameters of font and font are optional options II, case 1, case 1

Familiar with turtle coordinate system

# Import the turtle module import turtle as tt.goto (100100) t.goto (100mairelle 100) t.goto (- 100Mae Lashi 100) t.goto (- 100100) t.goto (0LING 0) t.done ()

2. Case 2

Brush automatic drawing

# using for cycle to realize automatic drawing of brushes import turtle as tfor i in range (20): # Brush moving forward t.forward (100 + 10 * I) # rotated 120 °t.right (120) t.done ()

3. Case 3

Show brush motion marks

# use for cycle to realize automatic drawing of brushes and display their imprints import turtle as tfor i in range (20): # Brush forward t.forward (100 + 10 * I) # t.shape ("turtle") # Turtles # t.shape ("circle") # Circle t.shape ("square") # Square # print turtle imprints t.stamp () # rotate 60 °t.right (60) t.done () clockwise

4. Case 4

Brush and fill control

# drawing the glittering sun import turtle as t # represents the proportion of the computer screen occupied by t.setup (width = 0.6, height = 0.6) # t.pencolor ("red") t.color ("red") "yellow") t.begin_fill () # Control drawing time t.speed (20) while True: t.forward (200) t.left (170) # print (t.pos ()) if abs (t.pos ()) < 1: breakt.end_fill () t.write ("a golden sun", align = "right", font = ("Arial", 20, "normal") t.done ()

5. Case 5

Draw a picture of a circle

# Pink Love import turtle as tt.setup (800800) t.speed (8) # set brush size t.pensize (10) t.hideturtle () t.pencolor ("pink") t.left (45) t.forward (80) t.circle (35210) t.right (35210) t.forward (80) t.done ()

The above is all the contents of the article "how to use python turtle drawing commands". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report