详解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)
猜你喜欢
省市级联菜单的可用性
2009-02-24 16:32:00
CSS的书写顺序规范
2008-06-12 13:51:00
扫盲大讲堂:mysql出错的代码解析及解答
2009-09-05 10:08:00
详解python使用Nginx和uWSGI来运行Python应用
2023-07-25 20:40:55
Python基于pygame实现单机版五子棋对战
2021-02-26 05:53:54
![](https://img.aspxhome.com/file/2023/4/65974_0s.jpg)
全屏flash的尺寸分析
2009-02-11 13:22:00
![](https://img.aspxhome.com/file/UploadPic/20092/11/01-11s.jpg)
oracle逻辑运算符与其优先级简介
2023-07-15 00:28:26
PHP错误提示的关闭方法详解
2023-11-14 13:00:05
asp如何直接调用Excel数据?
2010-06-28 18:26:00
Python3利用SMTP协议发送E-mail电子邮件的方法
2023-10-12 17:39:32
![](https://img.aspxhome.com/file/2023/2/63202_0s.jpg)
关于浏览器地址栏的小图标favicon.ico制作
2010-03-07 15:57:00
python flask开发的简单基金查询工具
2023-10-29 21:35:42
![](https://img.aspxhome.com/file/2023/0/66800_0s.png)
鼠标双击滚动屏幕单击停止代码
2008-02-21 11:44:00
设置SQLServer数据库中某些表为只读的多种方法分享
2012-07-11 15:41:05
什么设计师应该学习编写代码[译]
2009-07-08 14:58:00
![](https://img.aspxhome.com/file/UploadPic/20097/8/11-01_designers_code_leading_img-13s.jpg)
什么是SVG(可升级矢量图形)
2008-05-06 12:37:00
asp去除html的函数代码分析附实例说明
2023-07-02 20:09:18
Data URI小试 —— 在旺旺点灯(JS)上的应用
2009-10-30 18:28:00
![](https://img.aspxhome.com/file/UploadPic/200910/30/wangwang_v2-93s.gif)
Python 类的私有属性和私有方法实例分析
2021-06-18 05:13:47
Python选课系统开发程序
2023-07-21 00:25:03
![](https://img.aspxhome.com/file/2023/3/70693_0s.png)