python库——Turtle
Python turtle
2023-09-14 09:00:00 时间
Turtle库是Python中非常常用的绘制图像函数库
画笔状态
penup():抬起画笔;
pendown():落下画笔;
pensize(width):画笔宽度;
画笔运动
forward(d)/fd(d): 向前移动距离d backward(d)/bd(d): 向后移动距离d left(angle):向左转angle度; right(angle):向右转angle度; goto(x,y):移动到绝对位置; home() : 移动到原点; circle(r, extent = None):绘制半径为r,角度为extent的弧形; setheading(angle)/seth(angle):改变前进方向; undo():撤销最后的动作; speed():将速度设置为0..10范围内整数;
eg:
太阳花
from turtle import * color('red', 'yellow') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done()
平安果
from turtle import * setup(600, 600, 0, 0) pensize(5) up() goto(0, -200) down() # 先画一个圆,并填充为红色 begin_fill() color("red") circle(radius=150) end_fill() # 画苹果把儿 color("brown") penup() goto(-90, 0) pendown() circle(180, 40) penup() setheading(105) goto(-20, 20) pendown() circle(180, 50) pendown() # 画左边叶子 begin_fill() color("green") circle(180, 50) setheading(-30) circle(180, 55) end_fill() # 画右边叶子 begin_fill() color("green") setheading(0) circle(180, 50) setheading(-180) circle(180, 50) end_fill() done()
玫瑰花
from turtle import * # 设置初始位置 penup() left(90) forward(200) pendown() right(90) # 花蕊 fillcolor("blue") begin_fill() circle(10,180) circle(25,110) left(50) circle(60,45) circle(20,170) right(24) forward(30) left(10) circle(30,110) forward(20) left(40) circle(90,70) circle(30,150) right(30) forward(15) circle(80,90) left(15) forward(45) right(165) forward(20) left(155) circle(150,80) left(50) circle(150,90) end_fill() # 花瓣1 left(150) circle(-90,70) left(20) circle(75,105) setheading(60) circle(80,98) circle(-90,40) # 花瓣2 left(180) circle(90,40) circle(-80,98) setheading(-83) # 叶子1 forward(30) left(90) forward(25) left(45) fillcolor("green") begin_fill() circle(-80,90) right(90) circle(-80,90) end_fill() right(135) forward(60) left(180) forward(85) left(90) forward(80) # 叶子2 right(90) right(45) fillcolor("green") begin_fill() circle(80,90) left(90) circle(80,90) end_fill() left(135) forward(60) left(180) forward(60) right(90) circle(200,60) done()
红旗
from turtle import * setup(600, 400, 0, 0) bgcolor("red") fillcolor("yellow") color('yellow') speed(10) # 主星 begin_fill() up() goto(-280, 100) down() for i in range(5): forward(150) right(144) end_fill() # 副星一 begin_fill() up() goto(-100, 180) setheading(305) down() for i in range(5): forward(50) left(144) end_fill() # 副星二 begin_fill() up() goto(-50, 110) setheading(30) down() for i in range(5): forward(50) right(144) end_fill() # 副星三 begin_fill() up() goto(-40, 50) setheading(5) down() for i in range(5): forward(50) right(144) end_fill() # 副星四 begin_fill() up() goto(-100, 10) setheading(300) down() for i in range(5): forward(50) left(144) end_fill() hideturtle() done()
相关文章
- Python_cmd的各种实现方法及优劣(subprocess.Popen, os.system和commands.getstatusoutput)
- Python+Eclipse+PyDev安装
- 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
- Python操作符重载
- 【Python】python对象与json相互转换
- Python视觉深度学习系列教程 第三卷 第14章 从头开始训练Faster R-CNN
- 5 个 Python 代码来自动化你的日常工作,网友:早知道就好了
- Python语言学习之打印输出那些事:python输出图表和各种吊炸天的字符串或图画、版权声明(如README.md)等之详细攻略
- Python语言编程学习:利用python输出当前python版本、MSC版本型号
- Python 实现个人博客系统(附零基础python学习资料)
- 【python】鞭炮快乐响,春联贴门上,祝福送到你身旁
- 【阶段三】Python机器学习15篇:机器学习项目实战:支持向量机回归模型
- 修改python的pip源为国内源
- Python编程:python中的计时器timeit模块
- Python:mysql-connector-python模块对MySQL数据库进行增删改查
- python 可变参数
- 一文2000字手把手教你基于Python的UI自动化测试自学路线
- Python编程与实际运用
- 【Python】Visual Studio Code 安装&&使用 hello python~~~~
- 【Leetcode刷题Python】102. 二叉树的层序遍历
- 使用 OpenCV 和 Python 识别数字
- Python练习---turtle绘图之绘制天安门
- python中with的用法