Draw a HelloWorld with Python turtle Library

EthaneHike 2021-11-25 12:24:47
draw helloworld python turtle library

First draw a sketch

Determine the width and height of the picture （ The width and height of the frame are different from the actual width and height ） Then pass the brush through goto The function moves to the starting point , That is, the red dot in the figure , The coordinates of this point are （-550,80）.

then , It's painting , Basically, I use circle Function to draw an arc , Pay attention to the direction and radius and the radian of the arc .

Running results

Code implementation

``````#PythonDraw.py
import turtle as tu
tu.speed(0)
tu.pensize(5)
tu.setup(1280,720)
tu.penup()
tu.goto(-550,80)
tu.pendown()
tu.seth(20)
#H
tu.fd(50)
tu.circle(-3,120)
tu.circle(-300,30)
tu.circle(-30,220)
tu.fd(170)
tu.circle(30,220)
tu.circle(200,35)
tu.circle(30,120)
tu.fd(70)
#e
tu.circle(15,180)
tu.circle(35,100)
tu.circle(15,60)
tu.circle(60,30)
#l
tu.circle(200,40)
tu.circle(20,180)
tu.circle(200,35)
tu.circle(20,100)
#l
tu.circle(20,10)
tu.circle(200,40)
tu.circle(20,180)
tu.circle(200,35)
tu.circle(20,100)
#o
tu.circle(200,18)
tu.left(180)
tu.circle(30,360)
tu.circle(10,130)
tu.circle(100,30)
tu.circle(200,25)
#W
tu.circle(-50,120)
tu.circle(-30,50)
tu.circle(-200,10)
tu.circle(195,15)
tu.left(180)
tu.circle(-130,60)
tu.left(200)
tu.circle(70,60)
tu.circle(30,100)
tu.circle(150,50)
tu.circle(30,120)
tu.circle(50,120)
tu.circle(60,30)
tu.circle(50,40)
tu.circle(500,1)
tu.circle(30,50)
#o
tu.circle(-30,360)
tu.circle(-15,100)
tu.circle(100,20)
tu.circle(20,50)
tu.circle(200,10)
#r
tu.circle(-10,160)
tu.circle(200,12)
tu.circle(5,140)
tu.circle(100,10)
tu.circle(-200,20)
#l
tu.circle(200,20)
tu.circle(20,180)
tu.circle(100,30)
tu.circle(300,10)
tu.circle(25,100)
tu.circle(50,10)
tu.circle(100,20)
tu.fd(50)
#d
tu.circle(-50,60)
tu.left(180)
tu.circle(40,100)
tu.circle(20,120)
tu.circle(60,30)
tu.circle(200,30)
tu.circle(20,180)
tu.circle(200,30)
tu.circle(20,100)
tu.circle(50,15)
tu.fd(20)
#end
tu.penup()
tu.fd(1000)
tu.done()``````

circle The function is to draw an arc , The first parameter is the radius of the arc , In pixels , Positive values draw an arc to the left of the current brush direction , Negative values are on the right . The second parameter is the radian of the arc , The value is 360 That is, draw a circle .

fd（forward Abbreviation ） The function draws a straight line forward , The parameter is the length of the line , In pixels .

penup and pendown The function is to lift and drop the brush , When the brush is lifted and moved, it will not leave handwriting on the drawing board , But when you move when you fall, the handwriting will be displayed .

seth Function to set the absolute angle of the brush direction , In the same way as polar coordinates .

pensize Function to set the width of the brush , In pixels .

speed Function to set the painting speed , Parameter is 1-10 Time speed increment ,0 The fastest .

done Function to draw the end , Keep the drawing board and content .

https://pythonmana.com/2021/11/20211109010849492Q.html