python中使用turtle庫繪制圖形,具體方法如下:
1.繪制一個正方形
import turtle as tt.screensize(600,600."green")
t.color("yellow","red")
t.pensize(5)
t.speed(1)
#設置坐標起點
t.goto(0,0)
#開始繪制
for _ in range(4):
t.fd(150)
t.right(90)
t.stamp()
t.done()
2.繪制一個五角星
import turtleimport time
turtle.pensize(5)
turtle.pencolor("yellow")
turtle.fillcolor("black")
tuetle.begin_fill()
for _ in range(6)
turtle.forward(200)
turtle.right(144)
turtle.end_fill()
time.sleep(2)
tuetle.penup()
tuetle.goto(-150,-120)
turtle.color("violet")
turtle.write("Done",font=('Arial',40,'normal'))
time.sleep(1)
turtle.done()