turtle是python自带的画图的一个库,很强大。
运行效果图:

下面就用这个库绘制一个小猪佩奇,直接上代码

from turtle import*
def nose(x,y):penup()goto(x,y)pendown()setheading(-30)begin_fill()a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08left(3) forward(a) else:a=a-0.08left(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.4for i in range(60):if 0<=i<30 or 60<=i<90:a=a+0.08left(3) forward(a) else:a=a-0.08left(3)forward(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()setheading(90)forward(-25)setheading(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 body(x,y):color("red",(255,99,71))penup()goto(x,y)pendown()begin_fill()setheading(-130)circle(100,10)circle(300,30)setheading(0)forward(230)setheading(90)circle(300,30)circle(100,3)color((255,155,192),(255,100,100))setheading(-135)circle(-80,63)circle(-150,24)end_fill()
def hands(x,y):color((255,155,192))penup()goto(x,y)pendown()setheading(-160)circle(300,15)penup()setheading(90)forward(15)setheading(0)forward(0)pendown()setheading(-10)circle(-20,90)penup()setheading(90)forward(30)setheading(0)forward(237)pendown()setheading(-20)circle(-300,15)penup()setheading(90)forward(20)setheading(0)forward(0)pendown()setheading(-170)circle(20,90)
def foot(x,y):pensize(10)color((240,128,128))penup()goto(x,y)pendown()setheading(-90)forward(40)setheading(-180)color("black")pensize(15)forward(20)pensize(10)color((240,128,128))penup()setheading(90)forward(40)setheading(0)forward(90)pendown()setheading(-90)forward(40)setheading(-180)color("black")pensize(15)forward(20)
def tail(x,y):pensize(4)color((255,155,192))penup()goto(x,y)pendown()setheading(0)circle(70,20)circle(10,330)circle(70,30)
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) #嘴body(-32,-8) #身体hands(-56,-45) #手foot(2,-177) #脚tail(148,-155) #尾巴done() #结束
if __name__ == '__main__':main()

用python自动绘制小猪佩奇相关推荐

  1. python画图小猪佩奇_啥是佩奇?使用Python自动绘画小猪佩奇的代码实例

    最近社会猪可是火遍了大江南北,不蹭下热度可对不起它.见过手画的佩奇,见过用代码画的吗? 没有?那就来看我大显身手. 用python的turtle库来画小猪佩奇. 有人问:turtle难不难? 答曰:不 ...

  2. python设置笔大小的函数_小朋友们,你试过用Python语言绘制小猪佩奇吗?来完成你的第一个创作吧!...

    在上一章中,我们用海龟绘图绘制了机器猫的卡通图像.在本章中,我们介绍如何用海龟绘图来绘制小朋友们喜欢的另一个卡通形象--小猪佩奇. 1 程序分析 我们先来看一下小猪佩奇的样子,如图1所示. 图1 观察 ...

  3. 用python画小猪佩奇的编码有注释_啥是佩奇?使用Python自动绘画小猪佩奇的代码实例...

    最近社会猪可是火遍了大江南北,不蹭下热度可对不起它.见过手画的佩奇,见过用代码画的吗? 没有?那就来看我大显身手. 用python的turtle库来画小猪佩奇. 有人问:turtle难不难? 答曰:不 ...

  4. 用python画小猪佩奇的编码_如何用python绘制小猪佩奇-python绘图教程图文讲解

    原标题:如何用python绘制小猪佩奇-python绘图教程图文讲解 如何运用python来绘制小猪佩奇呢?通过几道简单的python代码即可让你绘制出小猪佩奇,话不多说,直接上代码. 用python ...

  5. Python|Python简介|安装Python解释器|运行|开发工具|Python之禅|turtle绘制五星红旗|绘制方块|绘制小猪佩奇|语言100课:学习(1)

    文章目录 源项目地址 初识Python Python简介 Python的历史 Python的优缺点 Python的应用领域 安装Python解释器 运行Python程序 确认Python的版本 编写P ...

  6. python turtle画熊-Python使用turtle库绘制小猪佩奇(实例代码)

    turtle(海龟)是Python重要的标准库之一,它能够进行基本的图形绘制.turtle图形绘制的概念诞生于1969年,成功应用于LOGO编程语言. turtle库绘制图形有一个基本框架:一个小海龟 ...

  7. python绘制小猪佩奇程序设计大作业_代码绘制一只小猪佩奇---python篇

    今天教大家用python的pillow包来绘制小猪佩奇,python的安装就不用多说了,直接上代码吧 0.首先当然是安装pillow包啦. 关于pillow库的安装有几种方式 最常使用的是pip安装 ...

  8. python turtle 绘图小猪佩奇,Python使用turtle库绘制小猪佩奇(实例代码)

    这篇文章主要介绍了Python使用turtle库绘制小猪佩奇,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下 turtle(海龟)是Python重要的标准库之一,它 ...

  9. 趣味python | 一步一步绘制小猪佩奇

    微信公众号:Python 集中营 简单的事情重复做,重复的事情坚持做,坚持的事情用心做; 你的肯定是我坚持的动力,如果这篇文章对你有帮助,点个关注吧! 定义全局属性 1# 导入turtle绘图库23i ...

最新文章

  1. 收藏 | Google 发布关于机器学习工程的最佳实践
  2. 2020十大新兴技术揭晓!每一项都可能颠覆我们的生活
  3. java字符数统计_【JAVA300例】51、统计输入的字符串中各种字符的字符数
  4. python怎么用excel-如何用python打开excel
  5. IPC之IPC_PRIVATE与ftok比较
  6. 几天后自动领取java怎么做的_java获取几天前和几天后的日期
  7. 学习笔记之-MySql高级之sql优化
  8. 网易云信自研大规模传输网核心系统架构剖析
  9. 【uoj#37/bzoj3812】[清华集训2014]主旋律 状压dp+容斥原理
  10. 论文浅尝 | 基于深度强化学习将图注意力机制融入知识图谱推理
  11. XShell远程连接LInux服务器(地址端口映射方法)
  12. python模块下载过程_常用的python模块及安装方法
  13. WebService只能在本地使用,无法通过网络访问的解决办法
  14. 交换机端口呈现err-disable的原因
  15. 深入理解l内核v4l2框架之video for linux 2(转载)
  16. 8个JavaScript题目
  17. Hadoop环境搭建(全网最详细,保姆级教程)
  18. vue显示PDF文件
  19. 当程序员工作七年之后的一点重要的总结
  20. 减法公式运算法则_减法的运算法则

热门文章

  1. 大数据培训:Spark 性能调优详解
  2. 常用邮箱、网盘地址列表
  3. Node与namespace
  4. 【C语言】极坐标转换为直角坐标
  5. python在国内外研究现状_国内外研究现状,水平和发展趋势-开题报告
  6. Java实现数据库读写分离
  7. Program Files可以删除吗?绝对不可以!
  8. 【BAT】pushd、popd命令
  9. 阿里2020.4.1实习笔试题——攻击怪兽
  10. 新手摸爬滚打:vue+springboot前后端分离项目演示(三)——axios实现前后端交互