用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 ...
随机推荐
- 多线程下不重复读取SQL Server 表的数据
在进行一些如发送短信.邮件的业务时,我们经常会使用一个表来存储待发送的数据,由后台多个线程不断的从表中读取待发送的数据进行发送,发送完成后再将数据转移到历史表中,这样保证待发送表的数据一般情况下不会太 ...
- C#技术点--修改系统时间
C#的System.DateTime类提供了对日期时间的封装,用它进行时间的转换和处理很方便,但是我没有在其中找到任何可以用来修改系统时间的成员.用过VC.VB等的朋友可能知道,我们可以调用Win32 ...
- Web前端开发学习笔记(二)
Homework2:http://my.ss.sysu.edu.cn/wiki/display/WEB/Homework+2+-+Movie+Review 这份作业跟布局相关,因此很多都是布局的知识: ...
- JavaScript设计模式(8)-装饰者模式
装饰者模式 1. 作用: 可用来透明地把对象包装在具有同样接口的另一对象之中,这样可以给一个方法添加一些行为,然后将方法调用传递给原始对象. 可用于为对象增加功能,用来代替大量子类. 装饰者对其组件进 ...
- PhotoShop制作简单的文字动画--多媒体技术与应用
下面是最终实现的效果图: 1.新建图像,设置图像属性如下所示. 2.使用[横排文字工具]在背景图像上打上文字内容 3.[图层]——>[图层式样]——>[渐变叠加] 出现“图层样式”面板 4 ...
- ES6常用知识点小结
ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准. 因为当前版本的ES6是在2015年发布的,所以又称ECMAScript 2015(简称ES2015).虽然浏览器在不 ...
- 搞定导致CPU爆满的“罪魁祸首”
昨天,正忙着,一个用户来电,说一个系统非常缓慢,导致整个系统无法正常使用,必须马上处理,先看系统资源,通过用户反馈的信息,内存,IO没问题,CPU资源严重紧张,idle持续为零,堆积任务达几百个,系统 ...
- C# QQ邮箱注册,以及数秒
一. 这是前台需要的东西 <asp:TextBox ID="Textemail" runat="server" CssClass="nonein ...
- 24.Django路由规则
路由规则 1.基于正则的url 在templates目录下创建index.html.detail.html文件 (1)index.html <!DOCTYPE html> <html ...
- Java单例模式的5种实现方式
1.饿汉式.不支持并发: package com.ou; //饿汉式 public class Singleton1 { private Singleton1() { } private static ...