用python画小猪佩奇的编码_如何用python绘制小猪佩奇-python绘图教程图文讲解
原标题:如何用python绘制小猪佩奇-python绘图教程图文讲解
如何运用python来绘制小猪佩奇呢?通过几道简单的python代码即可让你绘制出小猪佩奇,话不多说,直接上代码。
用python来绘制小猪佩奇
以下代码就是绘制小猪佩奇。复制代码或者到文末下载附件在python环境中运行即可实现绘制小猪佩奇,成为社会人的壮举。
"""
绘制小猪佩奇
"""
from turtle import *
def nose(x,y):
"""画鼻子"""
penup()
# 将海龟移动到指定的坐标
goto(x,y)
pendown()
# 设置海龟的方向(0-东、90-北、180-西、270-南)
setheading(-30)
begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i <90:
a = a + 0.08
# 向左转3度
left(3)
# 向前走
forward(a)
else:
a = a - 0.08
left(3)
forward(a)
end_fill()
penup()
setheading(90)
forward(25)
setheading(0)
forward(10)
pendown()
# 设置画笔的颜色(红, 绿, 蓝)
pencolor(255, 155, 192)
setheading(10)
begin_fill()
circle(5)
color(160, 82, 45)
end_fill()
penup()
setheading(0)
forward(20)
pendown()
pencolor(255, 155, 192)
setheading(10)
begin_fill()
circle(5)
color(160, 82, 45)
end_fill()
def head(x, y):
"""画头"""
color((255, 155, 192), "pink")
penup()
goto(x,y)
setheading(0)
pendown()
begin_fill()
setheading(180)
circle(300, -30)
circle(100, -60)
circle(80, -100)
circle(150, -20)
circle(60, -95)
setheading(161)
circle(-300, 15)
penup()
goto(-100, 100)
pendown()
setheading(-30)
a = 0.4
for i in range(60):
if 0<= i < 30 or 60 <= i < 90:
a = a + 0.08
lt(3) #向左转3度
fd(a) #向前走a的步长
else:
a = a - 0.08
lt(3)
fd(a)
end_fill()
def ears(x,y):
"""画耳朵"""
color((255, 155, 192), "pink")
penup()
goto(x, y)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10, 120)
circle(-50, 54)
end_fill()
penup()
setheading(90)
forward(-12)
setheading(0)
forward(30)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10, 120)
circle(-50, 56)
end_fill()
def eyes(x,y):
"""画眼睛"""
color((255, 155, 192), "white")
penup()
setheading(90)
forward(-20)
setheading(0)
forward(-95)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
color((255, 155, 192), "white")
penup()
seth(90)
forward(-25)
seth(0)
forward(40)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
def cheek(x,y):
"""画脸颊"""
color((255, 155, 192))
penup()
goto(x,y)
pendown()
setheading(0)
begin_fill()
circle(30)
end_fill()
def mouth(x,y):
"""画嘴巴"""
color(239, 69, 19)
penup()
goto(x, y)
pendown()
setheading(-80)
circle(30, 40)
circle(40, 80)
def setting():
"""设置参数"""
pensize(4)
# 隐藏海龟
hideturtle()
colormode(255)
color((255, 155, 192), "pink")
setup(840, 500)
speed(10)
def main():
"""主函数"""
setting()
nose(-100, 100)
head(-69, 167)
ears(0, 160)
eyes(0, 140)
cheek(80, 10)
mouth(-20, 30)
done()
if __name__ == '__main__':
main()
用python来绘制小猪佩奇
用python来绘制小猪佩奇
用python来绘制小猪佩奇
将以上文件保存到.py文件中,运行即可实现用python绘制小猪佩可的效果,以上就是羽忆教程网为你分享的用python画小猪佩奇的相关内容,想了解更多可以关注我们羽忆教程网。
文章转载自https://www.stmyw.cn/pythonhuitu/179.html返回搜狐,查看更多
责任编辑:
用python画小猪佩奇的编码_如何用python绘制小猪佩奇-python绘图教程图文讲解相关推荐
- 用python画小动物大全_python3用turtle库进行绘制小猪佩奇图案
晚上闲着无事,深入学习这个turtle用法,就做了小猪佩奇图 附上代码: # coding: utf-8 #功能:绘画小猪佩奇 import turtle as t t.screensize(400, ...
- 用python画六边形并填充颜色_如何用Python,画一个正多边形,长度和颜色还是任意的!...
Python画基本形状,要用到自带的turtle库,这是个简单绘图的入门小工具. 任务设定如上,下面来一点点拆解它. 从键盘获取用户输入的边数. 画笔形状由原来的三角形,改为海龟形状. 长度随机产生, ...
- 用python画小猪佩奇的编码_如何用Python代码画小猪佩奇
Python语言的功能太强大了,可以制作出很多想想的作品来,不信吗?用Python代码还可以画出小猪佩奇,代码其实很简单的,下面,就将几个关键步骤代码分享出来. 怎么用Python代码画小猪佩奇? 首 ...
- python画三角形并涂色_如何用python画叠加三角形?
python中可以使用下面的程序实现画叠加三角形:import turtle def drawTriangle(num,len,flag):#flag用来调整画三角形的方向 flag*=-1 len/ ...
- 用python画函数的梯度图_只需45秒,用Python给故宫画一组雪景手绘图
原标题:只需45秒,用Python给故宫画一组雪景手绘图 导读:最近故宫总能"摊上事". 今天是元宵节,一批幸运鹅拿着在故宫门票预售网站瘫痪之前抢来的门票,夜游故宫,成为94年来第 ...
- python画三维立体图完整代码_如何用Matplotlib 画三维图的示例代码
最基本的三维图是由(x, y, z)三维坐标点构成的线图与散点图,可以用ax.plot3D和ax.scatter3D函数来创建,默认情况下,散点会自动改变透明度,以在平面上呈现出立体感 三维的线图和散 ...
- python设置笔大小的函数_小朋友们,你试过用Python语言绘制小猪佩奇吗?来完成你的第一个创作吧!...
在上一章中,我们用海龟绘图绘制了机器猫的卡通图像.在本章中,我们介绍如何用海龟绘图来绘制小朋友们喜欢的另一个卡通形象--小猪佩奇. 1 程序分析 我们先来看一下小猪佩奇的样子,如图1所示. 图1 观察 ...
- 用python画五角星中心颜色不同_画个五角星让它绕中心点旋转
李兴球Python画个五角星绕中心点旋转 画一个五角星让它旋转起来,这在Python中有几个方案可选,这里提供一个不是用自定义形状的方案,以下是部分源代码, 其实关键的代码函数,也就是starpoin ...
- python画正方形并涂色_关于python使用cv画矩形并填充颜色同时填充文字
原博文 2017-05-08 12:18 − font = cv2.FONT_HERSHEY_SIMPLEX # 使用默认字体 cv2.rectangle(im, (10, 10), (110, 11 ...
最新文章
- Hibernate 的Set、List、Map集合操作(添加,修改,查询)
- 震惊!上手就是快,GitHub18.5K标星,超实用的Python资源
- 判断文件是否存在一个API函数
- 友情提示,你该找一份假期实习啦!
- SAP License:MM自动过账科目特殊库存杂谈
- WindowsXP如何设置共享权限
- Ubuntu设置静态IP/网关
- 自己写的BMFont导入工具,快速把图片转换为美术字体
- t检验的显著性p值python_t检验中的t值和p值是什么关系_t检验和p值的关系
- 架构师的岗位职责和要求
- 高斯消元法的c语言编程,用C语言编程高斯全主元消元法
- 作为一名APP开发者,你更Care什么?
- 中国最具影响力的10位画家:八大山人
- 2021年N1叉车司机考试题库及N1叉车司机模拟考试
- netty报Unknown channel option ‘TCP_NODELAY‘ for channel异常
- 一款很好用的,免费的外网映射工具Ngrok 国内版,可以满足基本的开发测试需求
- 戴尔Optiplex-7080装ubuntu16.04双系统时遇到的一些坑
- layuiAdmin 框架iframe基础常用方法事件文档
- 小墨机器人HTD-Robot-003 Root教程
- 江铖:乳腺癌识别By AI
热门文章
- 【日常】记一次烦人的Apple Airport Express Base Station配置
- 华山论剑——北大青鸟重庆大学城校区“五一”海报设计大赛
- 《Protein Actions Principles and Modeling》-《蛋白质作用原理和建模》中文分享(6)
- 城市旅游景点信息交流平台的设计与实现 毕业设计-附源码290915
- win10安装破解软件提示病毒并且删除安装软件,暂时关闭安全检查
- matlab与excel标准差不一样,matlab计算结果和excel完全不一样
- TableLayout——表格布局
- 实现输出h264直播流的rtmp服务器 flash直播服务器
- 非接触式的LED照明系统设计报告
- 《魔兽世界》法师的幽默