python turtle库
turtle库初步
先看 https://www.cnblogs.com/chy8/p/9448606.html
一 turtle库介绍
turtle乌龟
import turtle
from turtle import *
二 turtle库使用基本流程
分三步,打开冰箱门,放入冰箱,关门。
#落笔
turtle.down()
#开始绘制
#建立窗口
turtle.setup(宽度,高度,x,y)
#指定方向向前
turtle.forward()
turtle.fd()
#指定方向角度
turtle.left()
turtle.ritht()
#画圆
turtle.circle(size,rad)
三 常用函数
#指定画笔宽度和颜色
turtle.pensize()
turtle.pencolor()
#结束后必须有此代码,否则闪退
turtle.done()
turtle
在命令行下```python -m pip install turtle```
大致有两种命令:
运动命令:
forward(distance) #向前移动距离distance代表距离
backward(distance)#向后移动距离distance代表距离
right(degree) #向右移动多少度
left(degree) #向左移动多少度
goto(x,y) #将画笔移动到坐标为x,y的位置
stamp() #复制当前图形
speed(speed) #画笔绘制的速度范围[0,10]整数
画笔控制命令:
down() #落下画笔,默认是落下画笔,或者pendown()
up() #抬起画笔,或者penup()
pensize(width) #绘制图形时的宽度
color(colorstring) #绘制图形时的颜色
fillcolor(colorstring) #绘制图形的填充颜色
fill(Ture)
fill(false)
绘制填充三角形
from turtle import *
penup() # 抬起画笔
goto(0,10) # 移动到点(0,10)
pendown() # 落下画笔
begin_fill() # 开始填充
color("red") # 设置红色
circle(50,steps=3) # 绘制三角形
end_fill() # 结束填充
绘制填充五边形
from turtle import *
penup() # 抬起画笔
goto(-300,-100) # 去往点(-300,-100)
pendown() # 落下画笔
begin_fill() # 开始填充
color("green") # 设置绿色
circle(50,steps=5) # 绘制五边形
end_fill() # 结束填充
以此类推,可以绘制N边形
绘制正方形
from turtle import *
color("purple") # 定义画笔颜色
pensize(5) # 定义画笔的线条的宽度
speed(10) # 定义绘图的速度
penup() # 抬起画笔
goto(300, 250) # 以0,0为起点进行绘制
pendown() # 落下画笔
# 绘出正方形的四条边
for i in range(4):
forward(50)
right(90)
绘制五角星
from turtle import *
color("purple") # 设置紫色
pensize(5) # 设置画笔粗细
penup() # 抬起画笔
goto(-50, 350)
pendown() # 落下画笔
speed(5)
for i in range(6):
forward(100)
right(144)
penup() # 抬起画笔
forward(100) #right(216)
绘制心形
from turtle import *
pensize(3) # 设置画笔粗细
color('black', 'red')
speed(10)
penup() # 抬起画笔
goto(-12, 0)
pendown() # 落下画笔
begin_fill() # 开始填充红色
left(90) # 左转90度
circle(120, 180)
circle(360, 70.529)
left(38.942) # 左转
circle(360, 70.529)
circle(120, 180)
end_fill() # 结束填充红色
添加文字
from turtle import *
write("添加文字",font=("Times",18,"bold"))
原文链接:https://www.cnblogs.com/learnpy/p/6792213.html 作者:拾荒者
https://www.cnblogs.com/liutongqing/p/6834506.html 作者:tongqingliu
https://www.cnblogs.com/chy8/p/9448606.html 作者:chy8
python turtle库的更多相关文章
- Python turtle库详解
Python turtle库详解 Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在 ...
- Python turtle库的画笔控制说明
turtle.penup() 别名 turtle.pu() :抬起画笔海龟在飞行 turtle.pendown() 别名 turtle.pd():画笔落下,海龟在爬行 turtle.pensize(w ...
- Python Turtle库绘制蟒蛇
使用Python Turtle库来绘制蟒蛇 import turtle引入了海龟绘图体系 使用setup函数,设定了一个宽650像素和高350像素的窗体,其位置左上角坐标是200,200 说明位置在距 ...
- python turtle库的几个小demo
一.先上图 一个同切圆和五角星 上代码 import turtle #同切圆 turtle.pensize(2) turtle.circle(10) turtle.circle(40) turtle. ...
- Python turtle库学习笔记
1.简介 Python的turtle库的易操作,对初学者十分友好.对于初学者来说,刚学编程没多久可以写出许多有趣的可视化东西,这是对学习编程极大的鼓舞,可以树立对编程学习的信心.当然turtle本身也 ...
- Python turtle库绘制简单图形
一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...
- 第1课(续集),python turtle库的使用
原文再续,书接上一回 上回讲到了,python IDLE的草稿本和作业本,并顺便试了试python的输入输出,变量,运算的体验,大家应该能感受到python的简单了吧. 下面我们继续体验python的 ...
- 一篇文教你使用python Turtle库画出“精美碎花小清新风格树”快来拿代码!
Turtle库手册可以查询查询 python图形绘制库turtle中文开发文档及示例大全,手册中现有示例,不需要自己动手就可以查看演示. 使用Turtle画树,看了一下网上的代码,基本上核心的方法是使 ...
- Python turtle库的应用——蛇
turtle库介绍 1.Turtle中的turtle.setup()函数用于启动一个图形窗口,它有四个参数 turtle.setup(width, height, startx, starty) 分别 ...
随机推荐
- phxpaxos实现状态机CAS操作
看过了phxpaxos的实现,发现选主逻辑中非主也能够调用Propose.因此即使开启了选主功能,也可能会出现两个人同时Propose的场景.而Propose时,InstanceID只是作为输出而非输 ...
- 微信小程序 app.json文件配置
https://developers.weixin.qq.com/miniprogram/dev/index.html 起步 https://developers.weixin.qq.com/min ...
- H5-手机震动
//手机震动function vibration(){ navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navi ...
- asp.net mvc 使用NPOI插件导出excel
/// <summary> /// 交易账单 导出交易列表 /// </summary> /// <returns></returns> public ...
- html 分页
/*列表分页底部按钮*/ div.tablefooter{ color: #4f6d95; } select.pageLength{ border: 1px solid #d0daea; border ...
- 【笔记】Python基础七:正则表达式re模块
一,介绍 正则表达式(RE)是一种小型的,高度专业化的编程语言,在python中它内嵌在python中,并通过re模块实现.正则表达式模式被编译成一系列的字节码,然后由C编写的匹配引擎执行. 字符匹配 ...
- cnpm install -g live-server 安装服务
cnpm install -g live-server 指令会在浏览器自动打开页面
- Centos 7下网卡bonding配置之mode4
一.bonding技术 bonding(绑定)是一种linux系统下的网卡绑定技术,可以把服务器上n个物理网卡在系统内部抽象(绑定)成一个逻辑上的网卡,能够提升网络吞吐量.实现网络冗余.负载等功能,有 ...
- 20. Valid Parentheses (JAVA)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- sliding window:"Marginalization","Schur complement","First estimate jacobin"
[1]知行合一2 SLAM中的marginalization 和 Schur complement SLAM的Bundle Adjustment上,随着时间的推移,路标特征点(landmark)和相机 ...