操纵海龟绘图有着许多的命令,这些命令可以划分为两种:一种为运动命令,一种为画笔控制命令
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 画一朵花的更多相关文章

  1. 用内置的库turtle来画一朵花,python3

    题目:用内置的库turtle来画一朵花 看了群主最后成像的图片,应该是循环了36次画方框,每次有10度的偏移. 当然不能提前看答案,自己试着写代码. 之前有用过海龟画图来画过五角星.奥运五环.围棋盘等 ...

  2. Python画一朵花

    from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import Line ...

  3. python运用turtle 画出汉诺塔搬运过程

    python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...

  4. python3 turtle 画国际象棋棋盘

    python3 turtle 画国际象棋棋盘 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan import turt ...

  5. day 03 turtle 画鹅

    turtle 画鹅 import turtle t=turtle turtle.speed(10) t. setup(800,600) #画头 turtle.penup() turtle.goto(0 ...

  6. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  7. 【Python】【demo实验29】【练习实例】【使用turtle画五角星】

    原题: 使用turtle画五角星: 我的代码: #!/usr/bin/python # encoding=utf-8 # -*- coding: UTF-8 -*- from turtle impor ...

  8. 使用turtle库画一朵玫瑰花带文字

    参考链接:https://jingyan.baidu.com/article/d169e18689f309026611d8c8.html https://blog.csdn.net/weixin_41 ...

  9. python turtle画花

    turtle是一个功能强调大的绘图的库,可以用来绘制各种所需要的图案,但是在使用时需要计算好角度等一系列的问题. 代码(源自<Python语言程序设计>)如下: 运行结果:

随机推荐

  1. Shone.Math开源系列2 — 实数类型(含分数和无理数)的实现

    Shone.Math开源系列2 实数类型(含分数和无理数)的实现 作者:Shone 声明:原创文章欢迎转载,但请注明出处,https://www.cnblogs.com/ShoneSharp. 摘要: ...

  2. DOM变化后事件绑定失效

    第一个file在change时,是能够触发事件的,而第二插入的file则没有change事件.对于这个问题,有如下两种解决方法: 第一种是将绑定change事件封装成一个函数,在点击button按钮插 ...

  3. 通过adb调试Unity开发的安卓应用

    命令: 1. adb logcat -s Unity 2. adb | grep Unity

  4. Redis详解(九)------ 哨兵(Sentinel)模式详解

    在上一篇博客----Redis详解(八)------ 主从复制,我们简单介绍了Redis的主从架构,但是这种主从架构存在一个问题,当主服务器宕机,从服务器不能够自动切换成主服务器,为了解决这个问题,我 ...

  5. Python对象组合

    一个类的对象作为另一个类的对象的属性,称为类的组合. 即 class1.instance1.property = class2.instance 组合也是代码重用的重要方式之一. 先定义三个类:人.汽 ...

  6. [PHP工具推荐]0001.分析和解析代码的7大工具

    引言:PHP已成为时下最热门的编程语言之一,然而却有许多PHP程序员苦恼找不到合适的工具来帮助自己分析和解析PHP代码.今天SD就为大家介绍几个非常不错的工具,来帮助程序员们提高自己的工作效率,一起来 ...

  7. [Objective-C] 017_UI篇_UIView(中)

    在上篇我们简单讲了UIView的坐标与几何结构,这篇我们来实战UIView一下.UIView在App中有着绝对重要的地位,因为可视化控件几乎都是UIView的子类.在App负责渲染区域的内容,并且响应 ...

  8. MP4视频流base64数据转成Blob对象

    网上一大堆对图片base64转Blob.File的方法 很少有视频mp4转的,可能是因为原理相同的原因吧!但在项目中针对视频流base64转Blob对象时,花了好长时间才成功,特专门记录一下! APP ...

  9. POJ 2671 Jimmy's Bad Day题解(很详细很友好,类似区间dp)

    有问题的话欢迎在评论区提出 题意: 题目链接 你是一个送快递的,现在给你一个环,环的边有权值,代表走这条边所花的时间,每个点代表一个地点,点有点权,代表这个点上有多少货物需要你送.初始时间\(t=0\ ...

  10. Rocket - tilelink - Broadcast

    https://mp.weixin.qq.com/s/-pjCLzzincJz0Z66orx8kg   介绍Broadcast的实现.   ​​   1. 基本介绍   TLBroadcast实现的是 ...