详解python使用turtle库来画一朵花
作者:中华酷联 时间:2021-08-30 14:58:49
看了群主最后成像的图片,应该是循环了36次画方框,每次有10度的偏移。
当然不能提前看答案,自己试着写代码。
之前有用过海龟画图来画过五角星、奥运五环、围棋盘等,所以感觉不难。
# !/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:wxh
def run():
'''
主方法
:return: None
'''
import turtle
length = 150 # 线段长度
angle = 45 # 角度
offset_angle = 10 # 每次偏移的角度
turtle.screensize(800, 800)
turtle.bgcolor('blue')
def draw():
'循环画方框'
turtle.forward(length)
turtle.right(angle)
turtle.forward(length)
turtle.right(180 - angle)
turtle.forward(length)
turtle.right(angle)
turtle.forward(length)
turtle.right(180 - angle)
turtle.right(offset_angle)
turtle.penup()
turtle.goto(0, -400)
turtle.left(90)
turtle.pendown()
turtle.pencolor('gold')
turtle.forward(length * 3)
turtle.left(180)
for i in range(36):
draw()
turtle.hideturtle() # 隐藏画笔
turtle.done()
if __name__ == '__main__':
run()
最后是效果图:
以上所述是小编给大家介绍的python使用turtle库来画一朵花详解整合网站的支持!
来源:https://www.cnblogs.com/hiuhungwan/p/10557950.html
标签:python,turtle,画花
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 如何读、写、解析CSV文件
2022-09-21 13:59:33
![](https://img.aspxhome.com/file/2023/7/97627_0s.jpg)
Python 调用 Outlook 发送邮件过程解析
2023-11-17 19:34:57
![](https://img.aspxhome.com/file/2023/6/63536_0s.png)
javascript实现倒计时提示框
2024-04-22 22:30:35
![](https://img.aspxhome.com/file/2023/2/135682_0s.jpg)
PyTorch搭建LSTM实现时间序列负荷预测
2023-08-18 09:10:09
![](https://img.aspxhome.com/file/2023/9/76999_0s.png)
Safari参考样式库之webkit
2009-07-26 09:50:00
![](https://img.aspxhome.com/file/UploadPic/20097/26/webkit1-13s.jpg)
python实现地牢迷宫生成的完整步骤
2021-07-26 19:27:56
![](https://img.aspxhome.com/file/2023/4/131034_0s.png)
浅析python字符串前加r、f、u、l 的区别
2022-04-02 13:55:55
Python requests.post()方法中data和json参数的使用方法
2022-10-10 04:25:45
通过MySQL日志实时查看执行语句以及更新日志的教程
2024-01-17 03:57:10
ASPImage组件的实现过程[图]
2008-02-03 15:37:00
![](https://img.aspxhome.com/file/UploadPic/20082/3/200823154516685s.gif)
分享101个MySQL调试与优化技巧
2024-01-20 23:36:58
![](https://img.aspxhome.com/file/2023/3/120863_0s.jpg)
巧用Javascript的逻辑运算符
2024-04-16 09:47:42
python爬虫基础教程:requests库(二)代码实例
2023-05-31 07:56:35
python3.6使用SMTP协议发送邮件
2023-06-09 07:50:58
![](https://img.aspxhome.com/file/2023/8/101198_0s.jpg)
python如何解决指定代码段超时程序卡死
2023-01-12 04:04:10
![](https://img.aspxhome.com/file/2023/8/80508_0s.png)
解决Django数据库makemigrations有变化但是migrate时未变动问题
2024-01-15 16:55:39
![](https://img.aspxhome.com/file/2023/2/125202_0s.jpg)
Python时间差中seconds和total_seconds的区别详解
2022-10-04 15:00:49
JS+HTML5 canvas绘制验证码示例
2023-07-19 11:23:53
![](https://img.aspxhome.com/file/2023/3/55953_0s.png)
教你用YOLOv5实现多路摄像头实时目标检测功能
2022-12-27 08:51:14
![](https://img.aspxhome.com/file/2023/0/71360_0s.png)
在django项目中导出数据到excel文件并实现下载的功能
2023-09-10 08:31:43