​「Python绘图」绘制小猪佩奇

2024-04-24 18:36

本文主要是介绍​「Python绘图」绘制小猪佩奇,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

python 绘制小猪佩奇

一、预期结果

在这里插入图片描述

二、核心代码

import turtle
print("开始绘制小猪佩奇")
pen = turtle.Turtle()
pen.pensize(4)
#pen.hideturtle()pen.speed(1000)pen.color("#ff9bc0","pink")
pen.setheading(-30)
pen.pu()
pen.goto(-100,100)
pen.begin_fill()
pen.pd()
a=0.4
print("绘制鼻子")
for  i  in  range(120):if  0<=i<30  or  60<=i<90:a=a+0.08pen.lt(3)pen.fd(a)else:a=a-0.08pen.lt(3)pen.fd(a)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(25)
pen.setheading(0)
pen.fd(10)
pen.begin_fill()
pen.pd()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()
pen.pu()
pen.seth(0)
pen.fd(20)
pen.pd()
pen.pencolor("#ff9bc0")
pen.begin_fill()
pen.circle(5)
pen.color("#A0522D")
pen.end_fill()print("绘制头部")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(41)
pen.seth(0)
pen.pd()
pen.begin_fill()
pen.seth(0)
pen.circle(-300,30)
pen.circle(-100,60)
pen.circle(-80,100)
pen.circle(-150,20)
pen.circle(-60,95)
pen.seth(161)
pen.circle(-300,15)
pen.pu()
pen.goto(-100,100)
pen.pd()
pen.seth(-30)
a=0.4for  i  in  range(60):if  0<=i<30:a=a+0.08pen.lt(3)pen.fd(a)else:a=a-0.08pen.lt(3)pen.fd(a)
pen.end_fill()print("绘制耳朵")
pen.color("#ff9bc0","pink")
pen.pu()
pen.seth(90)
pen.fd(-7)
pen.seth(0)
pen.fd(70)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,54)
pen.end_fill()
pen.pu()
pen.seth(90)
pen.fd(-12)
pen.seth(0)
pen.fd(30)
pen.pd()
pen.begin_fill()
pen.seth(100)
pen.circle(-50,50)
pen.circle(-10,120)
pen.circle(-50,56)
pen.end_fill()pen.color("#ff9bc0","white")
pen.pu()
print("绘制眼睛")
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-95)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()
pen.color("#ff9bc0","white")
pen.pu()
pen.seth(90)
pen.fd(-25)
pen.seth(0)
pen.fd(40)
pen.pd()
pen.begin_fill()
pen.circle(15)
pen.end_fill()
pen.color("black")
pen.pu()
pen.seth(90)
pen.fd(12)
pen.seth(0)
pen.fd(-3)
pen.pd()
pen.begin_fill()
pen.circle(3)
pen.end_fill()print("绘制脸")
pen.color("#ff9bc0")
pen.pu()
pen.seth(90)
pen.fd(-95)
pen.seth(0)
pen.fd(65)
pen.pd()
pen.begin_fill()
pen.circle(30)
pen.end_fill()print("绘制嘴巴")
pen.color("#EF4513")
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(-100)
pen.pd()
pen.seth(-80)
pen.circle(30,40)
pen.circle(40,80)print("绘制身体")
pen.color("red","#FF6347")
pen.pu()
pen.seth(90)
pen.fd(-20)
pen.seth(0)
pen.fd(-78)
pen.pd()
pen.begin_fill()
pen.seth(-130)
pen.circle(100,10)
pen.circle(300,30)
pen.seth(0)
pen.fd(230)
pen.seth(90)
pen.circle(300,30)
pen.circle(100,3)
pen.color("#FF9BC0","#FF6464")
pen.seth(-135)
pen.circle(-80,63)
pen.circle(-150,24)
pen.end_fill()print("绘制胳膊")
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(-40)
pen.seth(0)
pen.fd(-27)
pen.pd()
pen.seth(-160)
pen.circle(300,15)
pen.pu()
pen.seth(90)
pen.fd(15)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-10)
pen.circle(-20,90)
pen.pu()
pen.seth(90)
pen.fd(30)
pen.seth(0)
pen.fd(237)
pen.pd()
pen.seth(-20)
pen.circle(-300,15)
pen.pu()
pen.seth(90)
pen.fd(20)
pen.seth(0)
pen.fd(0)
pen.pd()
pen.seth(-170)
pen.circle(20,90)print("绘制腿和脚")
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(-75)
pen.seth(0)
pen.fd(-180)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)
pen.pensize(10)
pen.color("#F08080")
pen.pu()
pen.seth(90)
pen.fd(40)
pen.seth(0)
pen.fd(90)
pen.pd()
pen.seth(-90)
pen.fd(40)
pen.seth(-180)
pen.color("black")
pen.pensize(15)
pen.fd(20)print("绘制尾巴")
pen.pensize(4)
pen.color("#FF9BC0")
pen.pu()
pen.seth(90)
pen.fd(70)
pen.seth(0)
pen.fd(95)
pen.pd()
pen.seth(0)
pen.circle(70,20)
pen.circle(10,330)
pen.circle(70,30)
# pen.mainloop()
# 隐藏画笔
pen.hideturtle()print("绘制完成")
turtle.done()

这篇关于​「Python绘图」绘制小猪佩奇的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/932522

相关文章

Python 字符串占位

在Python中,可以使用字符串的格式化方法来实现字符串的占位。常见的方法有百分号操作符 % 以及 str.format() 方法 百分号操作符 % name = "张三"age = 20message = "我叫%s,今年%d岁。" % (name, age)print(message) # 我叫张三,今年20岁。 str.format() 方法 name = "张三"age

以canvas方式绘制粒子背景效果,感觉还可以

这个是看到项目中别人写好的,感觉这种写法效果还可以,就存留记录下 就是这种的背景效果。如果想改背景颜色可以通过canvas.js文件中的fillStyle值改。 附上demo下载地址。 https://download.csdn.net/download/u012138137/11249872

一道经典Python程序样例带你飞速掌握Python的字典和列表

Python中的列表(list)和字典(dict)是两种常用的数据结构,它们在数据组织和存储方面有很大的不同。 列表(List) 列表是Python中的一种有序集合,可以随时添加和删除其中的元素。列表中的元素可以是任何数据类型,包括数字、字符串、其他列表等。列表使用方括号[]表示,元素之间用逗号,分隔。 定义和使用 # 定义一个列表 fruits = ['apple', 'banana

Python应用开发——30天学习Streamlit Python包进行APP的构建(9)

st.area_chart 显示区域图。 这是围绕 st.altair_chart 的语法糖。主要区别在于该命令使用数据自身的列和指数来计算图表的 Altair 规格。因此,在许多 "只需绘制此图 "的情况下,该命令更易于使用,但可定制性较差。 如果 st.area_chart 无法正确猜测数据规格,请尝试使用 st.altair_chart 指定所需的图表。 Function signa

python实现最简单循环神经网络(RNNs)

Recurrent Neural Networks(RNNs) 的模型: 上图中红色部分是输入向量。文本、单词、数据都是输入,在网络里都以向量的形式进行表示。 绿色部分是隐藏向量。是加工处理过程。 蓝色部分是输出向量。 python代码表示如下: rnn = RNN()y = rnn.step(x) # x为输入向量,y为输出向量 RNNs神经网络由神经元组成, python

python 喷泉码

因为要完成毕业设计,毕业设计做的是数据分发与传输的东西。在网络中数据容易丢失,所以我用fountain code做所发送数据包的数据恢复。fountain code属于有限域编码的一部分,有很广泛的应用。 我们日常生活中使用的二维码,就用到foutain code做数据恢复。你遮住二维码的四分之一,用手机的相机也照样能识别。你遮住的四分之一就相当于丢失的数据包。 为了实现并理解foutain

python 点滴学

1 python 里面tuple是无法改变的 tuple = (1,),计算tuple里面只有一个元素,也要加上逗号 2  1 毕业论文改 2 leetcode第一题做出来

Python爬虫-贝壳新房

前言 本文是该专栏的第32篇,后面会持续分享python爬虫干货知识,记得关注。 本文以某房网为例,如下图所示,采集对应城市的新房房源数据。具体实现思路和详细逻辑,笔者将在正文结合完整代码进行详细介绍。接下来,跟着笔者直接往下看正文详细内容。(附带完整代码) 正文 地址:aHR0cHM6Ly93aC5mYW5nLmtlLmNvbS9sb3VwYW4v 目标:采集对应城市的

python 在pycharm下能导入外面的模块,到terminal下就不能导入

项目结构如下,在ic2ctw.py 中导入util,在pycharm下不报错,但是到terminal下运行报错  File "deal_data/ic2ctw.py", line 3, in <module>     import util 解决方案: 暂时方案:在终端下:export PYTHONPATH=/Users/fujingling/PycharmProjects/PSENe

将一维机械振动信号构造为训练集和测试集(Python)

从如下链接中下载轴承数据集。 https://www.sciencedirect.com/science/article/pii/S2352340918314124 import numpy as npimport scipy.io as sioimport matplotlib.pyplot as pltimport statistics as statsimport pandas