前面写了一篇用turtle简单绘图,这一节再多学习几个turtle的函数,函数都比较简单,一看就明白的。首先贴一个小程序和运行结果,然后对其中用到的新函数做简单解释。
# draw various shapes
import turtle
turtle.showturtle()
turtle.pensize(3) # 1)
turtle.speed(10) # 2)
# draw polygon with 3 sides and fill with red
turtle.penup()
turtle.goto(-200,0)
turtle.pendown()
turtle.begin_fill() # 3)
turtle.color("red")
turtle.circle(50,steps=3) # 4)
turtle.end_fill() # 5)
# draw polygon with 5 sides and fill with green
turtle.penup()
turtle.goto(0,0)
turtle.pendown()
turtle.begin_fill()
turtle.color("green")
turtle.circle(50,steps=5)
turtle.end_fill()
# draw a polygon with 7 sides and fill with purple
turtle.penup()
turtle.goto(200,0)
turtle.pendown()
turtle.begin_fill()
turtle.color("purple")
turtle.circle(50,steps=7)
turtle.end_fill()
turtle.color("green")
turtle.penup()
turtle.goto(-25,100)
turtle.pendown()
turtle