吴裕雄--天生自然python编程:turtle模块绘图(3)
turtle(海龟)是Python重要的标准库之一,它能够进行基本的图形绘制。turtle图形绘制的概念诞生于1969年,成功应用于LOGO编程语言。
turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形。刚开始绘制时,小海龟位于画布正中央,此处坐标为(0,0),前进方向为水平右方。
Python——turtle库
turtle库包含100多个功能函数,主要包括窗体函数、画笔状态函数和画笔运动函数3类。
画笔运动函数
turtle通过一组函数控制画笔的行进动作,进而绘制形状 forward(distance) :别名 turtle.fd( distance ) 沿着当前方向前进指定距离
backward(distance) :别名 turtle.bk( distance ) 沿着当前相反方向后退指定距离 right(angle):改变画笔行进方向为当前方向向右旋转angle角度
left(angle):向左旋转angle角度 angle是角度相对值,角度的整数值 goto( x, y) :移动到画布中的特定位置(x, y)处 如果当前画笔处于落下状态,则绘制当前位置到目标位置的线条 setx( x ):修改画笔的横坐标到x,纵坐标不变
setx( y):修改画笔的纵坐标到y,横坐标不变 setheading( angle ):设置当前朝向为angle角度 别名 seth( angle )
注意:turtle库的角度坐标体系以正东方向为绝对0°,这也是小海龟的初始爬行方向,正西方向为绝对180°,这个方向坐标体系是方向的绝对方向体系,与小海龟爬向当前方向无关。
因此,可以利用这个绝对坐标体系随时更改小海龟的前进方向 home( ) :设置当前画笔位置为原点,朝向东
circle( r, e ):绘制一个指定半径 r 和角度e的圆或弧形
dot( r, color ):绘制一个指定半径 r 和颜色color的圆点
undo ( ):撤销画笔最后一步动作
speed( ):设置画笔的绘制速度,参数在0至10之间
from turtle import * setup(400,400)
penup()
goto(-100,50)
pendown()
color("red")
begin_fill() for i in range(5):
forward(200)
right(144) end_fill()
hideturtle()
done()
from turtle import * color('red','pink')
begin_fill()
left(135)
fd(100)
right(180)
circle(50,-180)
left(90)
circle(50,-180)
right(180)
fd(100)
end_fill()
hideturtle()
done()
import turtle n = 10
for i in range(1,10,1):
for j in [90,180,-90,0]:
turtle.seth(j)
turtle.fd(n)
n += 5
吴裕雄--天生自然python编程:turtle模块绘图(3)的更多相关文章
- 吴裕雄--天生自然python编程:正则表达式
re.match函数 re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回none. 函数语法: re.match(pattern, string, ...
- 吴裕雄--天生自然python编程:turtle模块绘图(1)
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行 ...
- 吴裕雄--天生自然python编程:turtle模块绘图(4)
import turtle bob = turtle.Turtle() for i in range(1,5): bob.fd(100) bob.lt(90) turtle.mainloop() im ...
- 吴裕雄--天生自然python编程:turtle模块绘图(2)
#彩色螺旋线 import turtle import time turtle.pensize(2) turtle.bgcolor("black") colors = [" ...
- 吴裕雄--天生自然python编程:实例(1)
str = "www.runoob.com" print(str.upper()) # 把所有字符中的小写字母转换成大写字母 print(str.lower()) # 把所有字符中 ...
- 吴裕雄--天生自然python编程:实例
# 该实例输出 Hello World! print('Hello World!') # 用户输入数字 num1 = input('输入第一个数字:') num2 = input('输入第二个数字:' ...
- 吴裕雄--天生自然python编程:pycharm常用快捷键问题
最近在使用pycharm的时候发现不能正常使用ctrl+c/v进行复制粘贴,也无法使用tab键对大段代码进行整体缩进.后来发现是因为安装了vim插件的问题,在setting里找到vim插件,取消勾选即 ...
- 吴裕雄--天生自然python编程:实例(3)
# 返回 x 在 arr 中的索引,如果不存在返回 -1 def binarySearch (arr, l, r, x): # 基本判断 if r >= l: mid = int(l + (r ...
- 吴裕雄--天生自然python编程:实例(2)
list1 = [10, 20, 4, 45, 99] list1.sort() print("最小元素为:", *list1[:1]) list1 = [10, 20, 1, 4 ...
随机推荐
- linux的/dev内容介绍
http://www.cnblogs.com/lidabo/p/4505360.html 这个结合那个linux的终端介绍 https://zhidao.baidu.com/question/1742 ...
- PAT Advanced 1056 Mice and Rice (25) [queue的⽤法]
题目 Mice and Rice is the name of a programming contest in which each programmer must write a piece of ...
- LaTeX Windows配置
1. 安装TeXstudio 用搜索引擎找合适的版本或者 在 https://sourceforge.net/projects/texstudio/ 下载 找合适的版本下载,点击下一步安装即可. Te ...
- Java web:html+css(2020.1.5)
html 1.font-size中1em=16px 2.html中font不要使用 3.链接标签<a></a>禁止下划线样式设置 <style> a{ color: ...
- Java远程调用Linux脚本
参考:http://blog.csdn.net/xiao_jun_0820/article/details/26254813 http://blog.csdn.net/a19881029/artic ...
- tf.boolean_mask
tf.boolean_mask 的作用是 通过布尔值 过滤元素 def boolean_mask(tensor, mask, name="boolean_mask", axis=N ...
- 17.3.15---关于GPIO控制流水灯的信息
添加一个网址: http://rmingwang.com/gpio-control-flow-lamp-code-archive.html 还有一个 http://www.openedv.com/po ...
- 吴裕雄--天生自然 PYTHON3开发学习:MongoDB
import pymongo myclient = pymongo.MongoClient("mongodb://localhost:27017/") mydb = myclien ...
- MFC的cstring判断是否存在中文字符
bool IsChinese(CString Cstr) { int nLen = Cstr.GetLength(); unsigned char ch1, ch2; for (int i = 0; ...
- 【二进制枚举+LCS】Card Hand Sorting
[二进制枚举+LCS]Card Hand Sorting 题目描述 When dealt cards in the card game Plump it is a good idea to start ...