如何利用python的turtle模块绘制各种多边形

本实例中要求编写一个python程序,掌握对turtle模块中绘制图形方法的使用

我们可以查阅到官方文档中的turtle中的文档,阅读相应的英文。

Turtle graphics is a popular way for introducing programming to
kids. It was part of the original Logo programming language developed
by Wally Feurzig and Seymour Papert in 1966.

Imagine a robotic turtle starting at (0, 0) in the x-y plane. After an ``import turtle``, give it
the command turtle.forward(15), and it moves (on-screen!) 15 pixels in
the direction it is facing, drawing a line as it moves. Give it the
command turtle.right(25), and it rotates in-place 25 degrees clockwise.

By combining together these and similar commands, intricate shapes and
pictures can easily be drawn.

 实例:绘制出一个多边形

import turtle
import time
i = 0
while(i<12):
    turtle.forward(100)
    turtle.right(200)
    time.sleep(2)
    i+=1

代码运行的成果:

总结:

1.turtle.forward(100)沿着箭头朝着的方向,向前移动100像素的距离,整个过程中箭头的朝向都没有发生变化。

2.turtle.right(200)箭头的朝向向右边偏移200度,没有产生位移。

3.forward方法和right()方法时turtle模块里面的一个很常用的两个方法,我们几乎可以利用它来绘制出所有的图形

就可以绘制出想要的各种多边形了,如果你还对机器学习,深度学习,数据结构和算法都很喜欢的话,可以订阅我的专栏,最后点个关注再走呗

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Li&&Tao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值