当前位置: 首页 > news >正文

Python画图之HelloKitty

Python-turtle画出HelloKitty(有趣小游戏)

  • 一、效果图
  • 二、安装库
    • 1.常用镜像源
    • 2.库下载
  • 三、Python代码

一、效果图

请添加图片描述

二、安装库

1.常用镜像源

1. 豆瓣http://pypi.douban.com/simple/
2. 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple 
3. 清华大学开源镜像站 https://mirrors.tuna.tsinghua.edu.cn/ 
4. 网易开源镜像站  http://mirrors.163.com/
5. 阿里巴巴开源镜像站 https://opsx.alibaba.com/mirror/
6. 华为开源镜像站:mirrors.huaweicloud.com/
7. 华中理工大学http://pypi.hustunique.com/simple/

2.库下载

#基础语句
pip install turtle
# 使用镜像源快速下载
pip install xxx -i http://pypi.douban.com/simple/
#如果出现错误,加入--user进去
pip install --user xxx -i http://pypi.douban.com/simple/

三、Python代码

import math
import turtle as t# 计算长度、角度 t1:画笔对象  r:半径  angle:扇形(圆形)的角度
def myarc(t1, r, angle):arc_length = 2 * math.pi * r * angle / 360  # angle角度的扇形的弧长n = int(arc_length / 3) + 1  # 线段条数step_length = arc_length / n  # 每条线段的长度step_angle = angle / n  # 每条线段的角度polyline(t1, n, step_length, step_angle)# 画弧线 t1:画笔对象  n:线段条数  length:每条线段长度  angle:每条线段的角度
def polyline(t1, n, length, angle):for index in range(n):t1.fd(length)t1.lt(angle)# 小花
def flower(n):for X in range(n):t.forward(0.5)if X < 80:t.left(1)elif X < 120:t.left(2.3)else:t.left(1)# 画布
t.screensize(500, 500, "white")
t.pensize(8)
t.pencolor("black")
t.speed(0) # 设置绘图速度为10
# t.tracer(1)  # 开启动画
#直接出结果
# wn = t.Screen()
# wn.tracer(0)# 头
t.penup()
t.goto(-130, 170)
t.pendown()
t.setheading(220)
for x in range(580):t.forward(1)if x < 250:t.left(0.5)elif x < 350:t.left(0.1)else:t.left(0.5)# 耳朵
t.setheading(70)
for y in range(150):t.forward(1)if y < 80:t.left(0.2)elif y < 90:t.left(10)else:t.left(0.2)
t.setheading(160)
for y1 in range(140):t.forward(1)t.left(0.15)
t.setheading(140)
for y2 in range(157):t.forward(1)if y2 < 65:t.left(0.2)elif y2 < 75:t.left(8)else:t.left(0.5)t.pensize(5)
# 左眼睛
t.penup()
t.goto(-100, 60)
t.setheading(350)
t.pendown()
t.fillcolor("#000")
t.begin_fill()
step = 0.3
for i in range(2):for j in range(60):if j < 30:step += 0.02else:step -= 0.02t.forward(step)t.left(3)
t.end_fill()
# 右眼睛
t.penup()
t.goto(50, 40)
t.setheading(350)
t.pendown()
t.fillcolor("#000")
t.begin_fill()
step = 0.3
for i in range(2):for j in range(60):if j < 30:step += 0.02else:step -= 0.02t.forward(step)t.left(3)
t.end_fill()
# 鼻子
t.penup()
t.goto(-40, 30)
t.setheading(260)
t.pendown()
t.fillcolor("#ebc80e")
t.begin_fill()
step = 0.3
for i in range(2):for j in range(60):if j < 30:step += 0.02else:step -= 0.02t.forward(step)t.left(3)
t.end_fill()# 小花
t.penup()
t.goto(20, 180)
t.pendown()
t.fillcolor("#dd4a76")
t.begin_fill()
t.setheading(175)
flower(200)
t.setheading(250)
flower(200)
t.setheading(325)
flower(200)
t.setheading(40)
flower(200)
t.setheading(115)
flower(170)
t.end_fill()
t.penup()
t.goto(30, 180)
t.setheading(270)
t.pendown()
t.fillcolor("#e7be04")
t.begin_fill()
t.circle(10)
t.end_fill()
# 胡子
t.penup()
t.goto(-150, 65)
t.pendown()
t.setheading(170)
t.pensize(6)
for y in range(40):t.forward(1)t.left(0.3)t.penup()
t.goto(-150, 85)
t.pendown()
t.setheading(160)
for y in range(50):t.forward(1)t.left(0.3)t.penup()
t.goto(-150, 45)
t.pendown()
t.setheading(180)
for y in range(55):t.forward(1)t.left(0.3)t.penup()
t.goto(110, 10)
t.setheading(340)
t.pendown()
for y in range(40):t.forward(1)t.right(0.3)
t.penup()
t.goto(120, 30)
t.setheading(350)
t.pendown()
for y in range(30):t.forward(1)t.right(0.3)
t.penup()
t.goto(115, 50)
t.setheading(360)
t.pendown()
for y in range(50):t.forward(1)t.right(0.3)# 身子
t.pensize(8)
t.penup()
t.goto(-100, -30)
t.setheading(230)
t.pendown()
t.fillcolor("#efa9c1")
t.begin_fill()
for z in range(140):t.forward(1)t.left(0.2)
t.setheading(340)
for z in range(200):t.forward(1)t.left(0.1)
t.setheading(85)
for z in range(140):t.forward(1)t.left(0.1)
t.end_fill()
t.penup()
t.goto(-73, -33)
t.pendown()
t.setheading(250)
t.fillcolor("#da4b76")
t.begin_fill()
myarc(t, 40, 205)
t.setheading(170)
t.pensize(6)
t.forward(75)
t.end_fill()
# 左胳膊
t.pensize(8)
t.penup()
t.goto(-120, -17)
t.setheading(230)
t.pendown()
t.fillcolor("#d64b75")
t.begin_fill()
t.forward(50)
t.setheading(320)
for k in range(27):t.forward(1)t.left(1)
t.setheading(55)
for k in range(50):t.forward(1)t.right(0.1)
t.end_fill()
# 左手
t.penup()
t.goto(-125, -15)
t.setheading(140)
t.pendown()
t.fillcolor("#fff")
t.begin_fill()
t.forward(8)
t.setheading(50)
myarc(t, 10, 190)
t.setheading(150)
for j in range(80):t.forward(1)t.left(2.2)
t.forward(24)
t.end_fill()
# 右胳膊
t.penup()
t.goto(27, -45)
t.pendown()
t.fillcolor("#db4e79")
t.setheading(350)
t.begin_fill()
for x in range(50):t.forward(1)t.right(1)
t.setheading(220)
t.forward(40)
t.setheading(100)
for x in range(50):t.forward(1)t.left(0.2)
t.end_fill()
# 右手
t.penup()
t.goto(70, -75)
t.pendown()
t.setheading(300)
t.forward(8)
t.setheading(30)
for x in range(40):t.forward(1)t.right(5)
t.setheading(280)
for x in range(70):t.forward(1)t.right(2)
# 右脚
t.penup()
t.goto(-70, -180)
t.pendown()
t.setheading(250)
for x in range(30):t.forward(1)t.left(0.3)
for x in range(160):t.forward(1)if x < 30:t.left(3)elif x < 65:t.left(0.1)else:t.left(1)
# 左脚
t.penup()
t.goto(-150, -210)
t.setheading(340)
t.pendown()
t.fillcolor("#fff")
t.begin_fill()
step = 1.5
for i in range(2):for j in range(60):if j < 30:step += 0.1else:step -= 0.1t.forward(step)t.left(3)
t.end_fill()t.hideturtle()t.up()
t.goto(-500, 400)
t.down()
t.pencolor('pink')
t.write('TO:宝子', font=('宋体', 40, 'bold'))t.up()
t.goto(300, -460)
t.down()
t.pencolor('pink')
t.write('BY:Jorya', font=('宋体', 40, 'bold'))t.up()
t.goto(-300, -380)
t.down()
t.pencolor('pink')
t.write('HelloKitty', font=('宋体', 80, 'bold'))t.hideturtle()
t.mainloop()

相关文章:

  • overflow溢出属性、定位、前端基础之JavaScript
  • 手写一个uniapp的步骤条组件
  • OSPF高级特性2(特殊区域,聚合)
  • 【Linux基础IO篇】系统文件接口(1)
  • 大厂面试题-TCP协议为什么要设计三次握手?
  • Python selenium驱动下载,模块安装以及基本使用
  • fastadmin笔记,关联查询,下拉框,关联下拉框查询,编辑时下拉框默认值
  • ArcGIS制作土地利用现状图
  • 第5天:基础入门-资产架构amp;端口amp;应用amp;CDNamp;WAFamp;站库分离amp;负载均衡
  • Fabric二进制建链(客户端与节点主机分离)
  • 【MATLAB源码-第65期】基于matlab的OFDM/OTFS通信系统性能对比,输处误码率曲线;对比是否采用LDPC编码。
  • 自动驾驶算法(三):RRT算法讲解与代码实现(基于采样的路径规划)
  • 资源限流 + 本地分布式多重锁——高并发性能挡板,隔绝无效流量请求
  • 【DriveGPT学习笔记】自动驾驶汽车Autonomous Vehicle Planning
  • 决胜ACM算法竞赛:掌握Python编程的基石
  • Android开源项目规范总结
  • Brief introduction of how to 'Call, Apply and Bind'
  • ES6, React, Redux, Webpack写的一个爬 GitHub 的网页
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • oldjun 检测网站的经验
  • PAT A1120
  • TypeScript迭代器
  • Work@Alibaba 阿里巴巴的企业应用构建之路
  • Zepto.js源码学习之二
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 学习使用ExpressJS 4.0中的新Router
  • 用Python写一份独特的元宵节祝福
  • 优秀架构师必须掌握的架构思维
  • 正则表达式
  • Prometheus VS InfluxDB
  • 仓管云——企业云erp功能有哪些?
  • $GOPATH/go.mod exists but should not goland
  • $refs 、$nextTic、动态组件、name的使用
  • ( 用例图)定义了系统的功能需求,它是从系统的外部看系统功能,并不描述系统内部对功能的具体实现
  • (二开)Flink 修改源码拓展 SQL 语法
  • (附源码)ssm学生管理系统 毕业设计 141543
  • (附源码)小程序 交通违法举报系统 毕业设计 242045
  • (简单) HDU 2612 Find a way,BFS。
  • (转)fock函数详解
  • (转)视频码率,帧率和分辨率的联系与区别
  • (转贴)用VML开发工作流设计器 UCML.NET工作流管理系统
  • .mysql secret在哪_MySQL如何使用索引
  • .NET Compact Framework 多线程环境下的UI异步刷新
  • .NET Core 2.1路线图
  • .NET Core 控制台程序读 appsettings.json 、注依赖、配日志、设 IOptions
  • .Net IE10 _doPostBack 未定义
  • .net利用SQLBulkCopy进行数据库之间的大批量数据传递
  • .NET命名规范和开发约定
  • .NET使用存储过程实现对数据库的增删改查
  • .NET文档生成工具ADB使用图文教程
  • .Net中ListT 泛型转成DataTable、DataSet
  • .net中生成excel后调整宽度
  • .net专家(张羿专栏)
  • [.NET]桃源网络硬盘 v7.4
  • []使用 Tortoise SVN 创建 Externals 外部引用目录