Python turtle库绘制菱形的3种方式小结
作者:toto+ 时间:2022-04-10 14:08:19
绘制一个菱形四边形,边长为 200 像素。方法1和2绘制了内角为60和120度的菱形,方法3绘制了内角为90度的菱形。
方法1
import turtle as t
ls = [30,-30,-150,150]#菱形各边的画笔绝对角度列表
for i in range(4):
t.seth(ls[i]) #画笔转向相应绝对角度
t.forward(200)
t.done()
方法2
import turtle as t
t.right(-45) #起始顶点绝对角度设为正30度
for i in range(4): #画4边,转向4次
t.fd(200)
degree = 60*(1+i%2) #其他3顶点右转角度分别为60、120、60度
t.right(degree)
t.done()
效果图如下:
方法3
import turtle as t
t.circle(200,steps=4) #circle(r,steps)函数画半径为r圆的内切steps边形
效果图如下:
来源:https://blog.csdn.net/lzqg1990/article/details/88917549
标签:Python,turtle,菱形
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
标签明晰、有效
2010-01-18 12:22:00
Python3 能振兴 Python的原因分析
2021-01-11 06:44:12
常用的javascript设计模式
2023-08-18 06:54:27
Python百度指数获取脚本下载并保存
2023-01-05 23:47:44
![](https://img.aspxhome.com/file/2023/8/67878_0s.webp)
Mozilla专有JavaScript扩展之一(__noSuchMethod__)
2009-03-01 12:45:00
使用Numpy读取CSV文件,并进行行列删除的操作方法
2023-05-05 03:26:11
Python PCA降维的两种实现方法
2022-03-05 04:25:47
![](https://img.aspxhome.com/file/2023/7/99117_0s.png)
详解Python中Sync与Async执行速度快慢对比
2023-02-06 13:26:45
![](https://img.aspxhome.com/file/2023/8/92138_0s.png)
Python input输入超时选择默认值自动跳过问题
2023-02-22 07:22:40
![](https://img.aspxhome.com/file/2023/5/112995_0s.png)
python环境下安装opencv库的方法
2022-03-22 10:11:24
![](https://img.aspxhome.com/file/2023/0/84930_0s.png)
Python Web框架Flask中使用百度云存储BCS实例
2023-09-14 21:53:44
Python中http请求方法库汇总
2021-04-28 10:26:21
JS 替换和时间插件的结合使用方法
2013-08-19 16:50:31
python 使用tkinter+you-get实现视频下载器
2023-08-15 18:40:25
![](https://img.aspxhome.com/file/2023/0/81560_0s.png)
Python实现批量自动整理文件
2023-05-10 21:58:12
![](https://img.aspxhome.com/file/2023/7/110577_0s.png)
关于Python3的import问题(pycharm可以运行命令行import错误)
2022-11-11 11:34:11
![](https://img.aspxhome.com/file/2023/0/115690_0s.png)
Python Django框架url反向解析实现动态生成对应的url链接示例
2021-08-23 04:30:38
PHP asXML()函数讲解
2023-06-08 14:04:37
![](https://img.aspxhome.com/file/2023/1/55411_0s.png)
ASP UTF-8编码下字符串截取和获取长度函数
2011-03-30 10:52:00
python快速查找算法应用实例
2021-04-17 10:28:13