python画一朵彩色玫瑰花图片_使用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 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址:https://www.linuxidc.com/Linux/2019-02/157156.htm返回搜狐,查看更多
责任编辑:
python画一朵彩色玫瑰花图片_使用Python画一朵美丽的玫瑰花相关推荐
- python docx 合并文档 图片_使用python抓取大量简历文档内数据(word:docx;pdf;图片等)输出表格文件...
1. 文章背景描述: 近期公司有员工离职了,技术岗位的. 让HR招人,招聘进度也太慢了,实在等不及,就撸起袖子自己上.(之前从来没招聘过) 自己在某招聘网站注册后,花了若干人民币,短时间收到大量求职者 ...
- python对比不同大小的图片_使用Python 制作对比图片相似度的程序怎么比较?
展开全部 就是给出以下几个function的def 越多越好: 1. red_average(Picture) 算出pic众pixels的平均红3231313335323631343130323136 ...
- python 钉钉机器人发送图片_利用Python自动发送钉钉数据消息
现在大部分公司都使用钉钉作为内部的主要沟通工具,钉钉消息基本都上都能快速有效的被阅读,打开率会比邮件高上不少.所以准备使用钉钉来播报平台每日的成交额,并附上一些鼓励的话和图片.起到一个激励团队的作用 ...
- python替换指定位置word图片_用Python在word的指定位置插入图片(使用Python-docx包)...
1 2 首先,本实例是采用java语言的,需要进行xml操作,至于poi,docx4j这些,因为感觉不是文档不太好,要嘛就是操作不方便,而且英文就算了,主要是注释很少,让人云里雾里的.所以,嘿嘿,直接 ...
- 利用python批量爬取网页图片_使用python来批量抓取网站图片
今天"无意"看美女无意溜达到一个网站,发现妹子多多,但是可恨一个page只显示一张或两张图片,家里WiFi也难用,于是发挥"程序猿"的本色,写个小脚本,把图片扒 ...
- python docx 合并文档 图片_使用Python制作WORD报告
在前面一期文章 使用Pandas.Jinja和WeasyPrint制作pdf报告 中我分享了如何使用HTML模板来创建pdf报告的方法. 虽然pdf很不错,但更多的人实际上在用微软的WORD来操作文档 ...
- python将网页保存为图片_使用Python保存网页上的图片或者保存页面为截图
# -*- coding: UTF-8 -*- import os,re,urllib,uuid #首先定义云端的网页,以及本地保存的文件夹地址 urlPath='http://gamebar.com ...
- python 散点图点击链接图片_在Python和matplotlib中连接三维散点图中的两点
在这些点之间绘制线段:import matplotlib.pyplot from mpl_toolkits.mplot3d import Axes3D dates = [20020514, 20020 ...
- canvas全局合成画月牙_教你用Python将自己喜欢的图片转成字符画,居然还有动态的 - 松鼠爱吃饼干...
本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理 以下文章一级Python技术 ,作者派森酱 前言 字符画是一种由字母,标点或其他字 ...
最新文章
- QIIME 2用户文档. 16鉴定和过滤嵌合体序列q2-vsearch(2018.11)
- 给大家推荐一个.Net的混淆防反编译工具ConfuserEx
- java旋转爱心_p5.js临摹旋转爱心
- SAP 用户权限解析
- android 手动签名apk,记录手动签名APK的过程
- MATLAB学习笔记(六)
- Oracle 存储过程、存储函数 与原生 JDBC 调用
- Windows 手动与脚本自动重启Print Spooler打印服务
- commandname
- 北理工嵩天Python面向对象程序设计笔记
- 黄金比例在设计上的应用
- 厂家深度解读:采用凯夫拉中底的劳保鞋优点有哪些?
- 在 Linux中安装中文输入法
- Spring Web项目
- 右下角弹出广告 js,漂浮效果(兼容多浏览器)
- SVN、CVS、VSS区别
- hdu2048 错位排列
- 输出Tecplot格式的数据文件
- Yamale Python 包受高危的代码执行漏洞影响
- win7升级正版win10方法(精华篇)!
热门文章
- Cadence 16.6/17.2 经常卡死
- 计算机网络高频面试题最新版
- 计算机学院 M.T Dreamer 协会,预告 | 毕业季,不想挥手说再见
- 【文献调研】慢病患者就医行为预测:就医选择行为有哪些?预测什么?如何预测?慢病患者?
- verilog程序,ISE 10.1环境下,检查语法和仿真均可,综合出错“ this signal is connected to multiple drivers.”
- 基于pytorch的无需分割字符的车牌识别
- 基于springboot+vue的积分兑换系统
- 对部署在weblogic中的项目进行打版
- Hibernate 快速入门
- kafka 0.10.2.2配置acl