开个小灶——turtle 海龟图形
turtle 海龟图形
turtle数据库是python语言中最流行的绘制函数图形的数据库,绘制笔头像个小海龟,因此一般称为 海龟图形。海龟数据库的导入 import turtle
1 画布大小设置
turtle.screensize(canvwidth, canvheight, 'bg背景颜色')
turtle.setup(width,height) width and height 为整表示像素,为小数表示占据屏幕比例
2 画笔
2.1画笔属性
turtle.pensize() 设置画笔的宽度
turtle.pencolor() 设置画笔颜色
turtle.speed() 画笔的速度 [0,10] 逐渐增大
2.2 画笔的移动命令
import turtle as tl
tl.fd() 向前移动距离
tl.bd() 向后移动距离
tl.right() 顺时针旋转角度
tl.left() 逆时针旋转角度
tl.goto(x,y) 将画笔移动至(x,y) 处
tl.penup() 提起画笔 tl.pendown() 放下画笔 两者一般配套使用
tl.circle(半径,角度) 绘制圆弧,其中半径为正值,表示逆时针画
tl.dot(半径,‘颜色’) 指定一个点的大小和颜色
2.3 画笔的控制命令
tl.fillcolor(‘颜色’) 绘制图形的填充颜色
tl.color('pencolor','fillcolor') 同时设置两种颜色
tl.filling() 返回当前是否处于填充状态
tl.begin_fill() 开始填充
tl.end_fill() 停止填充
tl.hideturtle() and tl.showturtle() 隐藏和显示海龟箭头
2.4 全局控制命令
tl.clear() 清空turtle窗口
tl.reset() 重新设置turtle窗口
tl.undo() 撤销
tl.isvisible() turtle图像可见
tl.write('名称’,font=('字体',‘大小’,‘类型’))
tl.mainloop() tl.done() 循环
tl.delay( 数字) 绘制延迟毫秒数
3 实例
3.1五角星
import turtle as tl
tl.pensize(10)
tl.color('red','yellow') tl.begin_fill()
for i in range(5):
tl.fd(200)
tl.left(144)
tl.fd(200)
tl.right(72)
tl.end_fill() tl.penup()
tl.goto(-155,-255)
tl.color("violet")
tl.hideturtle()
tl.write("pentagram",font=('newtimes','35','normal')) tl.done()
3.2 螺旋线
import turtle as tl
import time
tl.pensize(2)
tl.bgcolor('black')
colors =[ 'yellow','red','green','purple',]
tl.tracer(False)
for i in range(400):
tl.fd(i*2)
tl.color(colors[i% 4])
tl.left(91)
tl.tracer(True) time.sleep(5)
turtle.tracer(False) turtle.tracer(True) 直接将绘制结果显示,略去中间绘制过程。
开个小灶——turtle 海龟图形的更多相关文章
- python中的turtle库(图形绘画库)
turtle绘图的基础知识:1. 画布(canvas) 画布就是turtle为我们展开用于绘图区域,我们可以设置它的大小和初始位置. 设置画布大小 turtle.screensize(canvwidt ...
- 小白学Python(20)—— Turtle 海龟绘图
Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行 ...
- turtle绘制图形
Example1: import turtle as t #初始设置画笔的宽度(size).颜色(color) t.pensize(5) t.pencolor("black") # ...
- python库之turtle(图形绘制) 开启新的快乐源泉
相信有不少人学习python 都是听了老前辈的推荐 “学python好,python有趣的代码多” 比如说画一只小狮子 这就是今天想要介绍的绘制图形库-turtle 如果也想这样画一只小狮子,或者其他 ...
- turtle海龟库
•turtle的使用 #设置窗体大小 startx,starty非必需,默认在屏幕中间 turtle.setup(width,height,startx,starty) #海龟到(x,y)坐标 tur ...
- 递归可视化之汉诺塔的动画实现(turtle海龟)
import turtle class Stack: def __init__(self): self.items = [] def isEmpty(self): def push(self, ite ...
- turtle海龟作图
个人心得:python这么火是有他的原因的,突然发现他的语言很有趣,库函数也很多. 这次是第一步,简单了解了一下turtle函数 import turtle import time def drawS ...
- 又开一坑,运动图形MoGraph for Unity
Fragment+random: Vertex+random, Vertex+plain Vertex+Sound Plexus like 写了个大概,暂时没这方面需求先放这边了. C4D原版片段和克 ...
- python中的turtle库绘制图形
1. 前奏: 在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块 ...
随机推荐
- 20180519001 - DataTable Group by功能参考
DataSet6 = DataSet1.Copy(); DataRow[] dr = DataSet6.Tables[0].Select(" 完工状态 = '完工异常' "); D ...
- JS中if判断 非空即为真 非0即为真
1.字符串参与判断时:非空即为真判断字符串为空的方法if(str!=null && str!=undefined && str !='')可简写为if(!str){ ...
- ElasticSearch(十二)删除数据插件delete-by-query
在ElasticSearch2.0之后的版本中没有默认的delete-by-query,想使用此命令需要安装这个插件. 首先需要进入ES的目录 [root@node122 elasticsearch] ...
- 动态令牌验证遇到的问题(判断用户长按backspace键)
因为最近负责泰康项目的前端工作,他们的登录需要进行安全验证,也就是所谓的双因素验证,即在OA平台登录过后,还需要安全部门发送安全令牌进行验证.令牌验证效果如下: 主要功能有:1.默认第一项focus. ...
- TCP/IP学习
1.TCP/IP网络包括两部分 ①传输协议 ②网络协议
- windows修改注册表添加开启自启动
快捷键win+R regedit 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 新建字符串值 C:\soft ...
- Markdown介绍
如何使用.md文件 本文档为Markdown格式,建议利用Visual Studio Code+ Markdown All in One插件修改.参考链接:基础mdbasic,高级mdextended
- HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ)
HDU 3085 Nightmare Ⅱ(噩梦 Ⅱ) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- openstack-ntp时间同步服务
ntp时钟同步服务 NTP 工作请求 (1) 客户端将采用随机端口向 NTP 服务器 (UDP:123) 发出时间同步请求 (2)NTP 服务器收到请求后会将发出调校时间 (3)NTP 客户端接收到 ...
- java mvn:安装jar包
mvn install:install-file -Dfile=fastdfs-client-java-1.27-SNAPSHOT.jar(路径) -DgroupId=org.csource -Dar ...