用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 ...
随机推荐
- 初试 Windows XP Embedded 系统开发1
目前 Windows PE(Preinstallation Environment)和 Windows XP Embedded 是可以脱离主机里的硬盘独立运行的 Windows 操作系统,Window ...
- Error: expected expression, got '}'
1.错误描述 Error: expected expression, got '}' .globalEval/<@http://localhost:8080/Sys/resource/globa ...
- DirectShow学习笔记总结
DirectShow是微软公司在ActiveMovie和Video for Windows的基础上推出的新一代基于COM(Component Object Model)的流媒体处理的开发包,9.0之前 ...
- 学习一之UML类图
前言 最近在学习程杰老师的<大话设计模式>,觉得非常不错,就做了一些学习笔记和总结.如果对设计模式很感兴趣的,可以直接阅读书籍,相信会有更多的收获. 本人小菜一枚,如果理解的不对的还请多多 ...
- ASP.NET CSS 小结
1.ASP.NET 引用CSS 1.Site.master里面设置webopt <webopt:bundlereferencerunat="server"path=" ...
- 【Luogu2711】小行星(网络流,最大流)
[Luogu2711]小行星(网络流,最大流) 题面 题目描述 星云中有n颗行星,每颗行星的位置是(x,y,z).每次可以消除一个面(即x,y或z坐标相等)的行星,但是由于时间有限,求消除这些行星的最 ...
- 最长k可重线段集问题
和那道可重区间集一样 不过这道题可能有垂直于x轴的线段,这就很烦了,直接连会有负环,判掉又会WA 可以想办法把r端点和l端点分开,又要保证答案不变 那么直接把区间l,r都乘以2,l=r时r++,否则l ...
- 回滚 - 每天5分钟玩转 Docker 容器技术(141)
kubectl apply 每次更新应用时 Kubernetes 都会记录下当前的配置,保存为一个 revision(版次),这样就可以回滚到某个特定 revision. 默认配置下,Kubernet ...
- 网页中输出HTML代码
>>>>>> mustache.js的解决方案 var entityMap = { '&': '&', '<': '<', '>' ...
- Eclipse Web项目配置
1.每次重开workspace都要重新配置一次 2.new web project之前配置 3.Windows-Preferences-(所有都要记得Apply) General Maven P. ...