前面写了一篇用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.write("shapes",font=("Times",18,"bold")) # 6)
turtle.hideturtle()

这篇博客介绍了Python turtle模块中的一些高级绘图函数,包括设置线条粗细、调整绘制速度、图形填充、圆形内多边形绘制、文本写入、箭头隐藏等。通过实例演示了这些函数的使用方法,帮助读者深入理解turtle库的更多功能。
最低0.47元/天 解锁文章
897

被折叠的 条评论
为什么被折叠?



