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()