怎么用python画花瓣_使用Python画一朵美丽的玫瑰花
turtle 是 Python 中一个强大的绘制图像的库,可以用来绘制各种图像,使用起来很方便。看看本文使用Python的turtle库画一朵美丽的玫瑰花,下面奉上源码。
但是需要计算各种角度、距离等,所以要想完成一幅复杂的图像还是有一定的难度的。
效果图
源码一
from turtle import *
import time
setup(600,800,0,0)
speed(0)
penup()
seth(90)
fd(340)
seth(0)
pendown()
speed(5)
begin_fill()
fillcolor('red')
circle(50,30)
for i in range(10):
fd(1)
left(10)
circle(40,40)
for i in range(6):
fd(1)
left(3)
circle(80,40)
for i in range(20):
fd(0.5)
left(5)
circle(80,45)
for i in range(10):
fd(2)
left(1)
circle(80,25)
for i in range(20):
fd(1)
left(4)
circle(50,50)
time.sleep(0.1)
circle(120,55)
speed(0)
seth(-90)
fd(70)
right(150)
fd(20)
left(140)
circle(140,90)
left(30)
circle(160,100)
left(130)
fd(25)
penup()
right(150)
circle(40,80)
pendown()
left(115)
fd(60)
penup()
left(180)
fd(60)
pendown()
end_fill()
right(120)
circle(-50,50)
circle(-20,90)
speed(1)
fd(75)
speed(0)
circle(90,110)
penup()
left(162)
fd(185)
left(170)
pendown()
circle(200,10)
circle(100,40)
circle(-52,115)
left(20)
circle(100,20)
circle(300,20)
speed(1)
fd(250)
penup()
speed(0)
left(180)
fd(250)
circle(-300,7)
right(80)
circle(200,5)
pendown()
left(60)
begin_fill()
fillcolor('green')
circle(-80,100)
right(90)
fd(10)
left(20)
circle(-63,127)
end_fill()
penup()
left(50)
fd(20)
left(180)
pendown()
circle(200,25)
penup()
right(150)
fd(180)
right(40)
pendown()
begin_fill()
fillcolor('green')
circle(-100,80)
right(150)
fd(10)
left(60)
circle(-80,98)
end_fill()
penup()
left(60)
fd(13)
left(180)
pendown()
speed(1)
circle(-200,23)
exitonclick()
效果图:
源码二
import turtle
import math
def p_line(t, n, length, angle):
"""Draws n line segments."""
for i in range(n):
t.fd(length)
t.lt(angle)
def polygon(t, n, length):
"""Draws a polygon with n sides."""
angle = 360 / n
p_line(t, n, length, angle)
def arc(t, r, angle):
"""Draws an arc with the given radius and angle."""
arc_length = 2 * math.pi * r * abs(angle) / 360
n = int(arc_length / 4) + 1
step_length = arc_length / n
step_angle = float(angle) / n
# Before starting reduces, making a slight left turn.
t.lt(step_angle / 2)
p_line(t, n, step_length, step_angle)
t.rt(step_angle / 2)
def petal(t, r, angle):
"""Draws a 花瓣 using two arcs."""
for i in range(2):
arc(t, r, angle)
t.lt(180 - angle)
def flower(t, n, r, angle, p):
"""Draws a flower with n petals."""
for i in range(n):
petal(t, r, angle)
t.lt(p / n)
def leaf(t, r, angle, p):
"""Draws a 叶子 and fill it."""
t.begin_fill() # Begin the fill process.
t.down()
flower(t, 1, r, angle, p)
t.end_fill()
def main():
window = turtle.Screen() # creat a screen
window.bgcolor("white")
window.title("draw a flower")
lucy = turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(3)
# lucy.speed(10)
# Drawing flower
flower(lucy, 7, 60, 100, 360)
# Drawing pedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200)
# Drawing leaf 1
lucy.width(1)
lucy.rt(270)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.rt(140)
lucy.color("black")
lucy.fd(30)
lucy.lt(180)
lucy.fd(30)
# Drawing leaf 2
lucy.rt(120)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.color("black")
lucy.rt(140)
lucy.fd(30)
lucy.ht() # hideturtle
window.exitonclick()
main()
怎么用python画花瓣_使用Python画一朵美丽的玫瑰花相关推荐
- python椭圆花瓣_用Python给你带来你的桃花运,详细解析画一棵表白树
程序员就只能简简单单的用手里的代码来实现自己最直接的想法.-------------鲁迅表示这句话他没说过 在家上网课贼无聊,于是复习以前的知识点,瞥到之前用递归实现的科赫曲线,突然来了一点头绪,上博 ...
- python画一朵彩色玫瑰花图片_使用Python画一朵美丽的玫瑰花
原标题:使用Python画一朵美丽的玫瑰花 turtle 是 python 中一个强大的绘制图像的库,可以用来绘制各种图像,使用起来很方便.看看本文使用Python的turtle库画一朵美丽的玫瑰花, ...
- 如何用python画一朵玫瑰花-使用Python画一朵美丽的玫瑰花
原标题:使用Python画一朵美丽的玫瑰花 turtle 是 python 中一个强大的绘制图像的库,可以用来绘制各种图像,使用起来很方便.看看本文使用Python的turtle库画一朵美丽的玫瑰花, ...
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
- Python使用turtle画一朵美丽的玫瑰花
turtle 是 Python中一个强大的绘制图像的库,可以用来绘制各种图像,看看本文使用Python的turtle库画一朵美丽的玫瑰花. 但是需要计算各种角度.距离等,所以要想完成一幅复杂的图像还是 ...
- 用python海龟制图画花瓣_Python竟能画这么漂亮的花,帅呆了(代码分享)
阅读本文大概需要3分钟 关于函数和模块讲了这么久,我一直想用一个好玩有趣的小例子来总结一下,同时也作为实战练习一下. 趣味编程其实是最好的学习途径,回想十几年前我刚毕业的时候,第一份工作就给手机上写a ...
- python canvas画弧度_用Python画樱花?想得美就能画得美(下)
上一篇我们介绍了一种手绘玫瑰的方法,你当然也可以用类似的方法画一朵或者几朵樱花 咯,看你的艺术底子了. 不过今天我们用优美的数学方法来画樱花,也会很漂亮的. 先画朵太阳花暖暖身吧. import tu ...
- python turtle 椭圆_【python turtle如何画椭圆】
python turtle画4个同心圆方法 from turtle import * def Circle(radius,angle,length): for i in range(length): ...
最新文章
- 用v-for循环动态定位坐标显示元素,并遍历元素的left和top坐标位置(只需要用到元素的宽高、索引、每行显示数量)
- java transient关键字_小伙子,你真的搞懂 transient 关键字了吗?
- debian/ubuntu 安装和使用perf
- 一篇综述带你全面了解迁移学习的领域泛化(Domain Generalization)
- python表白代码照片墙-python入会生成照片墙 利用python生成照片墙代码
- LeetCode 2156. 查找给定哈希值的子串(字符串哈希)
- SaaS服务的私有化部署,这样做最高效|云效工程师指北
- php ajax复选框是否选中的值,jquery-ajax - php+ajax分页时,checkbox复选框选中的问题...
- 使用Django的models创建mysql数据库
- redis循环键_Redis 性能优化的 13 条军规!史上最全
- Control Web Panel 中两个严重漏洞使Linux 服务器易受RCE攻击
- MFC函数——CWnd::OnCreate
- 腾讯Android自动化测试实战3.2.1 Robotium支持Native原理
- 交通指示牌的特征匹配代码
- 手机屏幕画面实时直播
- Mac 安装LaTeX教程 mactex+sublime+skim
- Coddington shape factor
- Promise对象的resolve回调函数和reject回调函数使用
- 蓝桥杯基础练习之 闰年判断 、 01字串 、查找整数、数列特征 、字母图形
- Bootstrap——网格布局