python(turtle库)画七巧板

这篇博客介绍如何在Python 3环境下利用turtle库来画出七巧板。通过运行代码,可以看到七巧板的形成过程,若要消除轨迹动画,可调整turtle库的speed属性。

#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属性进行修改。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值