用python程序来画花

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程序来画花的更多相关文章
- [daily][optimize] 一个小python程序的性能优化 (python类型转换函数引申的性能优化)
前天,20161012,到望京面试.第四个职位,终于进了二面.好么,结果人力安排完了面试时间竟然没有通知我,也没有收到短信邀请.如果没有短信邀请门口的保安大哥是不让我进去大厦的.然后,我在11号接到了 ...
- python运用turtle 画出汉诺塔搬运过程
python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...
- 3.第一个python程序
学习任何一门语言的第一步,首先要写个'hello world',这算是程序员的一个传统.但在写之前,还有注意几个问题. 首先,python是一门脚本语言,而脚本语言的特点就是:我们写的代码会先由解释器 ...
- 想拥有自己的Python程序包,你只需15步
来源商业新知网,原标题:15步,你就能拥有自己的Python程序包 全文共 3192 字,预计学习时长 6 分钟 每个软件开发员和数据科学家都难免要做程序包.本文推荐一篇 Python开源程序包的制作 ...
- 我的第一个Python程序,定义主函数,eval、format函数详解,
程序实例: #第一个py小程序 def main(): f = eval(input("输入一个数值:")) p=f*(5/9) print("现在的值为:{0:3.3f ...
- Python 开篇及第一个Python程序
本节内容 python 简单介绍 python 2.x 或者python 3.x python 安装 第一个python程序 一.python简单介绍 python的创始人为吉多.范罗苏姆(Guido ...
- Python程序调试工具Py-Spy
序言 如果你是从Java语言开发转Python开发,可能在庆幸自己的开发效率提高了很多,但是也有痛苦的时候,比如你会怀念jstack,jmap, 等各种工具在生产环境做perfomance tunin ...
- python应用(2):写个python程序给自己用
用python写一个程序,然后在命令行上执行,看不到界面(UI),这种程序很常见了,叫命令行程序.然而很多人,特别是不懂程序的人,更需要看到的是一个有界面的,能通过鼠标操作的程序,毕竟已经迈进&quo ...
- 运行python程序
1 在windows下运行python程序 1)从DOS命令行运行python脚本 用python解释器来执行python脚本,在windows下面python解释器是python.exe,我的pyt ...
随机推荐
- Java中的java.math.BigInteger
Java中的java.math.BigInteger /** * */ package com.you.model; /** * @author YouHaidong * */ public clas ...
- html标签自带样式总结
一.html标签自带样式 head { display:none; } body { margin:8px; line-height:1.12; } button, textarea, input, ...
- 谈谈在.NET Core中使用Redis和Memcached的序列化问题
前言 在使用分布式缓存的时候,都不可避免的要做这样一步操作,将数据序列化后再存储到缓存中去. 序列化这一操作,或许是显式的,或许是隐式的,这个取决于使用的package是否有帮我们做这样一件事. 本文 ...
- python urllib和urllib3包使用
urllib包 urllib是一个包含几个模块来处理请求的库.分别是: urllib.request 发送http请求 urllib.error 处理请求过程中,出现的异常. urllib.parse ...
- 【BZOJ4554】游戏(二分图匹配,网络流)
[BZOJ4554]游戏(二分图匹配,网络流) 题解 Description 在2016年,佳缘姐姐喜欢上了一款游戏,叫做泡泡堂.简单的说,这个游戏就是在一张地图上放上若干个炸弹,看 是否能炸到对手, ...
- canvas练手项目(一)——选取图片
今天无事可做,在春意盎然的下午突发奇想想做一个关于图片处理的在线网页应用.不要问我为什么做这个,因为我想做!关于这个项目,我想基于canvas来实现,canvas是个好东西,我一直很喜欢,就是我没有做 ...
- 八年架构师大咖首次揭秘,年薪50W秘籍!
序言 我是土生土长的老北京人,你们肯定觉得我很有钱,为啥呢? 因为觉得我是北京户口,其实你们错了,我的房子是靠我自己买的,父母基本上没帮到我什么,当然,我也不需要吧! 我只想说,作为一名程序员,我很自 ...
- JavaScript之事件及动画
一.事件 常用事件 click(function(){...}) //单击事件 hover(function(){...}) //鼠标经过事件 blur(function(){...}) //失去光标 ...
- 关于Web Audio API的入门
Web Audio API提供了一个简单强大的机制来实现控制web应用程序的音频内容.它允许你开发复杂的混音,音效,平移以及更多. 可以先看一下MDN的这篇文章<Web Audio API的运用 ...
- QT自定义控件插件化简要概述
1.选择 "其他项目"->"Qt4 设计师自定义控件" **最好选中所有的编译器平台,由于目前使用的Qt Creator是MSVC2015 32位,因此要 ...