turtle 画一朵花
操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
1. 运动命令:
forward(degree) #向前移动距离degree代表距离
backward(degree) #向后移动距离degree代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
2. 画笔控制命令:
down() #移动时绘制图形,缺省时也为绘制
up() #移动时不绘制图形
pensize(width) #绘制图形时的宽度
color(colorstring) #绘制图形时的颜色
fillcolor(colorstring) #绘制图形的填充颜色
fill(Ture)
fill(false)
lucy : 梦想照进现实;露茜;青春风采;
draw_flower1.py
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, 40, 80, 180)
t.end_fill() def main(): window=turtle.Screen() #creat a screen
window.bgcolor("blue")
lucy=turtle.Turtle()
lucy.shape("turtle")
lucy.color("red")
lucy.width(5)
lucy.speed(0) # Drawing flower
flower(lucy, 10, 40, 100, 360) # Drawing pedicel
lucy.color("brown")
lucy.rt(90)
lucy.fd(200) # Drawing leaf
lucy.rt(270)
lucy.color("green")
leaf(lucy, 40, 80, 180)
lucy.ht()
window.exitonclick() main()
执行结果:

turtle 画一朵花的更多相关文章
- 用内置的库turtle来画一朵花,python3
题目:用内置的库turtle来画一朵花 看了群主最后成像的图片,应该是循环了36次画方框,每次有10度的偏移. 当然不能提前看答案,自己试着写代码. 之前有用过海龟画图来画过五角星.奥运五环.围棋盘等 ...
- Python画一朵花
from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import Line ...
- python运用turtle 画出汉诺塔搬运过程
python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...
- python3 turtle 画国际象棋棋盘
python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...
- day 03 turtle 画鹅
turtle 画鹅 import turtle t=turtle turtle.speed(10) t. setup(800,600) #画头 turtle.penup() turtle.goto(0 ...
- *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】
如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...
- 【Python】【demo实验29】【练习实例】【使用turtle画五角星】
原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...
- 使用turtle库画一朵玫瑰花带文字
参考链接:https://jingyan.baidu.com/article/d169e18689f309026611d8c8.html https://blog.csdn.net/weixin_41 ...
- python turtle画花
turtle是一个功能强调大的绘图的库,可以用来绘制各种所需要的图案,但是在使用时需要计算好角度等一系列的问题. 代码(源自<Python语言程序设计>)如下: 运行结果:
随机推荐
- Poj2586 每五个月都是亏
题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个月不是盈利就是亏损(废话),而且无论是盈利和亏损都有一个定值(亏少了它还不干).经过 ...
- CPU上下文切换以及相关指标的理解
前言 上下文切换这个词一直不理解,看了无数遍就忘了无数遍,知道看到<操作系统导论>这本书,终于有了略微的理解.这也证明了我的方向是没错的,一直认为做运维还是得理解底层的知识,不理解很多 ...
- 关于pytest使用allure生成报告时,报一堆警告和缺少XX模块
因为最新的pytest 支持*.josn的用例报告,卸载旧的模块使用新的即可: 需要移除旧模块:pip uninstall pytest-allure-adaptor, 并安装:pip install ...
- Python中对文件的读写
读写文件前,我们先必须了解一下,在磁盘上读写文件的功能都是由操作系统提供的,现代操作系统不允许普通的程序直接操作磁盘. 读写文件就是请求操作系统打开一个文件对象(通常称为文件描述符),然后,通过操作系 ...
- Ant标签详解--基础操作
Ant的一些核心概念: build.xml:构建文件是以XML 文件来描述的,默认构建文件名为build.xml. project:每个构建文件包含一个工程. property:属性,一 ...
- [安卓基础] 005.创建一个简单的UI
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- shell script的简单使用
shell script的简单介绍 shell变量 1.命名规则 命名只能使用英文字母,数字和下划线,首个字符不能以数字开头 中间不能有空格,可以使用下划线(_) 不能使用标点符号. 不能使用bash ...
- Rocket - util - ReduceOthers
https://mp.weixin.qq.com/s/gbR5fuDbE_nUFVxw-p4rsA 简单介绍ReduceOthers的实现. 1. 基本介绍 输入一组Bool元素 ...
- Rocket - util - Broadcaster
https://mp.weixin.qq.com/s/ohBVNAXZUA538qSxfBGMKA 简单介绍Broadcaster的实现. 1. Broadcaster 广播即是 ...
- Rocket - diplomacy - ValName
https://mp.weixin.qq.com/s/so-2x5KLfYF0IMCCqNThwQ 简单调试ValName实现: 1. 使用 Desugar之后如下: ...