#python 3版本中运行,首先要引用turtle库
import turtle as t
t.speed(2)
t.pensize(0)
t.ht()
#绿色板块
t.color("green")
t.begin_fill()
t.goto(200,200)
t.goto(-200,200)
t.end_fill()
#蓝色板块
t.color("blue")
t.begin_fill()
t.goto(-200,-200)
t.goto(0,0)
t.end_fill()
#黄色板块
t.color("yellow")
t.begin_fill()
t.goto(100,-100)
t.goto(100,100)
t.end_fill()
#红色板块
t.color("red")
t.begin_fill()
t.goto(200,200)
t.goto(200,0)
t.goto(100,-100)
t.end_fill()
#紫色板块
t.color("purple")
t.begin_fill()
t.goto(0,0)
t.goto(-100,-100)
t.goto(0,-200)
t.end_fill()
#粉色板块
t.color("pink")
t.begin_fill()
t.goto(-100,-100)
t.goto(-200,-200)
t.goto(0,-200)
t.end_fill()
#橙色板块
t.color("orange")
t.begin_fill()
t.goto(200,-200)
t.goto(200,0)
t.end_fill()
#运行结果展示如下图所示:

#此图片在运行时会有轨迹的变化过程,如果不需要则可以对speed属性进行修改。
这篇博客介绍如何在Python 3环境下利用turtle库来画出七巧板。通过运行代码,可以看到七巧板的形成过程,若要消除轨迹动画,可调整turtle库的speed属性。

2653

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



