In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how python uses the Turtle library to draw and write names, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Turtle library is a very popular Python language to draw images of the library, using this library will generate a canvas, in the canvas we can not see a default to the center point as the origin of the axis, in the origin there will be an initial default to the east of the brush (arrow), we generally call this arrow turtle, the arrow is facing the head of the sea turtle.
This dynamic picture shows a name drawing I drew using the Turtle library, with the following code:
Import timeimport turtlefrom random import randomt = turtlet.speed (3) t.hideturtle () t.color ('black') t.pensize (10) #-t.penup () t.goto (- 110,60) t.pendown () t.forward (100) # | t.penup () t.goto (- 60,125) t.right (90) t.pendown () t.forward () #) t.penup () t.goto (- 60) 45) t.right (45) t.pendown () t.forward (90) #, t.penup () t.goto (- 60,38) t.left (90) t.pendown () t.forward (40) # Primary one t.penup () t.goto (20,60) t.left (45) t.pendown () t.forward (90) # | t.penup () t.goto (65) T.right (90) t.pendown () t.forward (123) # freshman t.penup () t.goto (0,-5) t.left (90) t.pendown () t.forward (130) # Primary one t.penup () t.goto (20,-65) t.pendown () t.forward (90) # | t.penup () t.goto (65) -14) t.right (90) t.pendown () t.forward (120) # freshman t.penup () t.goto (0,135) t.left (90) t.pendown () t.forward (130) # draw a circle t.color ('red') t.pensize (3) t.penup () t.goto (15,200) t.pendown () t.circle (180) t.exitonclick () function
explain
Hideturtle
Hide brushes
Speed
Brush speed, 1-10. 1 is the slowest, 10 is the fastest.
Color
After that, you can pass parameters (2 parameters), which is not passed as the default setting. The first parameter is the brush color and the second parameter is the fill color.
Pensize
The bigger the brush, the thicker it is.
Penup
Pick up the brush, and then do not draw the track when the brush moves
Pendown
By default, the brush falls, and then the brush will draw the track.
Forward (num)
Brush motion, num is the number of motion pixels, that is, length
Right (a)
Rotate an angle to the right and clockwise in the brush direction
Left (a)
Rotate an angle to the left and counterclockwise in the brush direction
Goto (XBI y)
Move the brush to the axis xpeny position, and the track will be drawn under pendowm
Goto (XBI y)
Move the brush to the axis xpeny position, and the track will be drawn under pendowm
Circle (a)
Draw a circle with a radius of an at the center of the current point
Exitonclick
Click close, and the brush will not automatically exit the canvas after running.
The following is a big guy's code for painting cherry trees seen in the forum. The result is much more complex than the above, but it is easy to understand when you understand my above code. As an advanced, it will be shown to you:
Import turtle as Timport randomimport time# painted the torso of cherry blossoms (60 branch t) def Tree (branch, t): time.sleep (0.0005) if branch > 3: if 8
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.