python turtle画圆、循环法_Python之turtle画同心圆和棋盘

画饼图

importturtle

t=turtle.Pen()for i in range(5):

t.penup()

t.goto(0,-i*30)

t.pendown()

t.circle(i*30+30)

turtle.done()

623088-20181104103559427-64191949.png

画棋盘

importturtle

t=turtle.Pen()

widthall= 200width= 20num= widthall // 20 * 2 + 1t.speed(10)for r inrange(num):

t.penup()

t.goto(-widthall, widthall - width *r)

t.pendown()

t.goto(widthall, widthall- width *r)for c inrange(num):

t.penup()

t.goto(-widthall + width *c, widthall)

t.pendown()

t.goto(-widthall + width * c, -widthall)

turtle.done()

623088-20181104103713713-1696790335.png

海龟绘图

绘制简单的五角星。

导入turtle模块

默认情况下,海龟的开始位置在窗口的中间,朝向右下方,笔是向下的。

然后,控制海龟进行多次转弯,画出线段。

星形的中心是正五边形,正五边形的每个内角为108°。

五个等腰山叫醒连接在五边形的外部。

因为五边形的一侧形成三角形延伸,每个三角形的底角为72°(补角:180°-108°)

等腰三角形的两个底角度数相同,加起来是144°。所以第三个角必须是36°。

为了实现急转弯,在星形的每个顶点需要转144°(即180°-36°)。

因此在每个顶点,有turtle.right(144)。

importturtle

t=turtle.Pen()

t.forward(100)

t.right(144)

t.forward(100)

t.right(144)

t.forward(100)

t.right(144)

t.forward(100)

t.right(144)

t.forward(100)

turtle.done()

623088-20181111171512417-1548745971.png

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值