博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开个小灶——turtle 海龟图形
阅读量:6903 次
发布时间:2019-06-27

本文共 1566 字,大约阅读时间需要 5 分钟。

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 tltl.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 tlimport timetl.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)  直接将绘制结果显示,略去中间绘制过程。

 

 

 

转载于:https://www.cnblogs.com/daimatuo/p/10437727.html

你可能感兴趣的文章
Codeforces Round #533(Div. 2) C.Ayoub and Lost Array
查看>>
HDU - 3966-Aragorn' Story(树链剖分+线段树)
查看>>
Linux基础第五章 进程控制
查看>>
[转载]孤儿进程与僵尸进程[总结]
查看>>
jquery事件机制扩展,jquery鼠标右键事件。
查看>>
windows phone Image checkbox
查看>>
[pycharm]远程调试服务器项目
查看>>
7 Java NIO Selector-翻译
查看>>
rvm 添加 Path
查看>>
All Users in SharePoint Site Custom Webpart
查看>>
pip下载源更换为豆瓣源
查看>>
Java多线程之先行发生原则(happens-before)
查看>>
React Render props
查看>>
自动类型转换
查看>>
C# winfrom 当前程序内存读取和控制
查看>>
电话号码分身
查看>>
Redis持久化方案
查看>>
Unity保存序列化数据
查看>>
测试jupyter notebook导出md格式的兼容性
查看>>
【转】WPF MultiBinding 和 IMultiValueConverter
查看>>