This article is participating in Python Theme Month. See the link to the event for more details
Hello, everybody. I found another interesting little thing today. I’m an old poem about funny gadgets.
As usual, start with the renderings
This is a small picture of the position drawn in Python. Drawing for tutle graphics library. Turtle Drawing is a powerful library for Python that can be used to draw a wide variety of patterns. It can even be used for specific UI design. The details are shown in the figure below:
The main API used for drawing is the following:
Method of Turtle Turtle move action and draw the forward () | fd () forward backward () | bk () | back | rt () () () the back right right left () | lt () left goto () | Setpos () | setposition () to/positioning your setx () sets the x coordinate sety () sets the y coordinate setheading () | Seth set toward home () () to return to the origin circle points painting circle dot () () Seal clearstamps seal clearstamp stamp () () () to remove multiple seal undo () cancel the speed () speed for the turtle state the position () | pos () position forward direction () goals Xcor () x coordinate ycor () y heading towards () short distance () set and the unit of measure degrees Angle radians () () arc control brush drawing state pendown | pd | down () () () Brush sets penup | pu | up () () () brush lift pensize () | width brush pen () () the brush thickness isdown () whether brush sets Color control color () pencolor () the brush color Fillcolor () FillColor Filling () Whether to fill begin_fill() Start filling end_fill() End filling more drawing control reset() Reset clear() Clear write() Write Turtle state visibility Showturtle | st () () shows that sea turtles hideturtle | ht () () to hide the turtle isvisible () is visible Shape resizemode appearance shape () () the size adjustment mode shapesize () | Turtlesize () shape size shearfactor() shearfactor settiltangle() set inclination tiltangle() tilt tilt() shapetransform() deformation get_shapepoly() Get shape polygonsCopy the code
Those who want to learn more about Tutle can go to their official API: Portal
Detailed code:
Import turtle import math t=turtle.pen() t=turtle t.pu () t.oto (0,150) t.own () t.color('red') t.bagin_fill () t.fillcolor('red') t.speed(1) t.left(45) t.forward(150) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(250+math.sqrt(2)*100) t.right (90) t.speed(2) t.forward(250+100*math.sqrt(2)) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(100) T.light (45) t.ward (150) t.nd_fill () t.light (-10,0) t.color ('white') #L t.light (10) t.light (-50,0) t.light (-50,80) T.u p () # I t.g oto t.d (100, 0) on () t.g oto (160, 0) t.g oto (130, 0) t.g oto (130) t.g oto (160) t.g oto t.u (100 -) p () #O t.oto (10,25) t.own () t.light (45) t.ircle (25,extent=180) t.oto (60,55) t.ircle (25,extent=180) t.oto (10,25) t.u () T.oto (75,80) t.oto () t.oto (100,0) t.oto (125,80) t.u () t.oto (180,80) t.oto () t.oto (140,80) t.oto (140,0) T.u t.g oto (180, 0) (p) t.g oto t.d (180, 40) on () t.g oto (140, 40) # U t.u p () t.g oto t.d (- 40-30) on () t.g oto (- 40-80), t.circle(40,extent=180) t.goto(40,-30) t.hideturtle() a=input()Copy the code
More learning materials, programming source code, please move to the public number: like the code poem. Since come in, liver text is not easy. Let’s go with a “like”.