python之小猪佩奇

小猪佩奇知识准备:
turtle模块:时间控制:turtle.speed(0)

  1 import turtle as t
  2
  3
  4 def running():
  5
  6     t.pensize(4)
  7     t.hideturtle()
  8     t.colormode(255)
  9     t.color((255, 155, 192), "pink")
 10     t.setup(840, 500)
 11     t.speed(10)
 12
 13     # 鼻子
 14     t.pu()
 15     t.goto(-100, 100)
 16     t.pd()
 17     t.seth(-30)
 18     t.begin_fill()
 19     a = 0.4
 20     for i in range(120):
 21         if 0 <= i < 30 or 60 <= i < 90:
 22             a = a + 0.08
 23             t.lt(3)  # 向左转3度
 24             t.fd(a)  # 向前走a的步长
 25         else:
 26             a = a - 0.08
 27             t.lt(3)
 28             t.fd(a)
 29     t.end_fill()
 30
 31     t.pu()
 32     t.seth(90)
 33     t.fd(25)
 34     t.seth(0)
 35     t.fd(10)
 36     t.pd()
 37     t.pencolor(255, 155, 192)
 38     t.seth(10)
 39     t.begin_fill()
 40     t.circle(5)
 41     t.color(160, 82, 45)
 42     t.end_fill()
 43
 44     t.pu()
 45     t.seth(0)
 46     t.fd(20)
 47     t.pd()
 48     t.pencolor(255, 155, 192)
 49     t.seth(10)
 50     t.begin_fill()
 51     t.circle(5)
 52     t.color(160, 82, 45)
 53     t.end_fill()
 54
 55     # 头
 56     t.color((255, 155, 192), "pink")
 57     t.pu()
 58     t.seth(90)
 59     t.fd(41)
 60     t.seth(0)
 61     t.fd(0)
 62     t.pd()
 63     t.begin_fill()
 64     t.seth(180)
 65     t.circle(300, -30)
 66     t.circle(100, -60)
 67     t.circle(80, -100)
 68     t.circle(150, -20)
 69     t.circle(60, -95)
 70     t.seth(161)
 71     t.circle(-300, 15)
 72     t.pu()
 73     t.goto(-100, 100)
 74     t.pd()
 75     t.seth(-30)
 76     a = 0.4
 77     for i in range(60):
 78         if 0 <= i < 30 or 60 <= i < 90:
 79             a = a + 0.08
 80             t.lt(3)  # 向左转3度
 81             t.fd(a)  # 向前走a的步长
 82         else:
 83             a = a - 0.08
 84             t.lt(3)
 85             t.fd(a)
 86     t.end_fill()
 87
 88     # 耳朵
 89     t.color((255, 155, 192), "pink")
 90     t.pu()
 91     t.seth(90)
 92     t.fd(-7)
 93     t.seth(0)
 94     t.fd(70)
 95     t.pd()
 96     t.begin_fill()
 97     t.seth(100)
 98     t.circle(-50, 50)
 99     t.circle(-10, 120)
100     t.circle(-50, 54)
101     t.end_fill()
102
103     t.pu()
104     t.seth(90)
105     t.fd(-12)
106     t.seth(0)
107     t.fd(30)
108     t.pd()
109     t.begin_fill()
110     t.seth(100)
111     t.circle(-50, 50)
112     t.circle(-10, 120)
113     t.circle(-50, 56)
114     t.end_fill()
115
116     # 眼睛
117     t.color((255, 155, 192), "white")
118     t.pu()
119     t.seth(90)
120     t.fd(-20)
121     t.seth(0)
122     t.fd(-95)
123     t.pd()
124     t.begin_fill()
125     t.circle(15)
126     t.end_fill()
127
128     t.color("black")
129     t.pu()
130     t.seth(90)
131     t.fd(12)
132     t.seth(0)
133     t.fd(-3)
134     t.pd()
135     t.begin_fill()
136     t.circle(3)
137     t.end_fill()
138
139     t.color((255, 155, 192), "white")
140     t.pu()
141     t.seth(90)
142     t.fd(-25)
143     t.seth(0)
144     t.fd(40)
145     t.pd()
146     t.begin_fill()
147     t.circle(15)
148     t.end_fill()
149
150     t.color("black")
151     t.pu()
152     t.seth(90)
153     t.fd(12)
154     t.seth(0)
155     t.fd(-3)
156     t.pd()
157     t.begin_fill()
158     t.circle(3)
159     t.end_fill()
160
161     # 腮
162     t.color((255, 155, 192))
163     t.pu()
164     t.seth(90)
165     t.fd(-95)
166     t.seth(0)
167     t.fd(65)
168     t.pd()
169     t.begin_fill()
170     t.circle(30)
171     t.end_fill()
172
173     # 嘴
174     t.color(239, 69, 19)
175     t.pu()
176     t.seth(90)
177     t.fd(15)
178     t.seth(0)
179     t.fd(-100)
180     t.pd()
181     t.seth(-80)
182     t.circle(30, 40)
183     t.circle(40, 80)
184
185     # 身体
186     t.color("red", (255, 99, 71))
187     t.pu()
188     t.seth(90)
189     t.fd(-20)
190     t.seth(0)
191     t.fd(-78)
192     t.pd()
193     t.begin_fill()
194     t.seth(-130)
195     t.circle(100, 10)
196     t.circle(300, 30)
197     t.seth(0)
198     t.fd(230)
199     t.seth(90)
200     t.circle(300, 30)
201     t.circle(100, 3)
202     t.color((255, 155, 192), (255, 100, 100))
203     t.seth(-135)
204     t.circle(-80, 63)
205     t.circle(-150, 24)
206     t.end_fill()
207
208     # 手
209     t.color((255, 125, 192))
210     t.pu()
211     t.seth(90)
212     t.fd(-40)
213     t.seth(0)
214     t.fd(-27)
215     t.pd()
216     t.seth(-160)
217     t.circle(300, 15)
218     t.pu()
219     t.seth(90)
220     t.fd(15)
221     t.seth(0)
222     t.fd(0)
223     t.pd()
224     t.seth(-10)
225     t.circle(-20, 90)
226
227     t.pu()
228     t.seth(90)
229     t.fd(30)
230     t.seth(0)
231     t.fd(237)
232     t.pd()
233     t.seth(-20)
234     t.circle(-300, 15)
235     t.pu()
236     t.seth(90)
237     t.fd(20)
238     t.seth(0)
239     t.fd(0)
240     t.pd()
241     t.seth(-170)
242     t.circle(20, 90)
243
244     # 脚
245     t.pensize(10)
246     t.color((112, 128, 128))
247     t.pu()
248     t.seth(90)
249     t.fd(-75)
250     t.seth(0)
251     t.fd(-180)
252     t.pd()
253     t.seth(-90)
254     t.fd(40)
255     t.seth(-180)
256     t.color("black")
257     t.pensize(15)
258     t.fd(20)
259
260     t.pensize(10)
261     t.color((240, 128, 128))
262     t.pu()
263     t.seth(90)
264     t.fd(40)
265     t.seth(0)
266     t.fd(90)
267     t.pd()
268     t.seth(-90)
269     t.fd(40)
270     t.seth(-180)
271     t.color("black")
272     t.pensize(15)
273     t.fd(20)
274
275     # 尾巴
276     t.pensize(4)
277     t.color((255, 155, 192))
278     t.pu()
279     t.seth(90)
280     t.fd(70)
281     t.seth(0)
282     t.fd(95)
283     t.pd()
284     t.seth(0)
285     t.circle(70, 20)
286     t.circle(10, 330)
287     t.circle(70, 30)
288     t.done()
289
290 running()

 
 

原文地址:https://www.cnblogs.com/kermitjam/p/9236652.html

时间: 2024-07-30 22:41:17

python之小猪佩奇的相关文章

运用python绘制小猪佩奇

用python绘制小猪佩奇 1.打开idle 2.点击File-New Files 3.输入以下代码 1. from turtle import * 2. 3. def nose(x,y):#鼻子 4. penup()#提起笔 5. goto(x,y)#定位 6. pendown()#落笔,开始画 7. setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东.90-北.180-西.270-南) 8. begin_fill()#准备开始填充图形 9. a=0.4 10.

用python画小猪佩奇(非原创)

略作改动: # coding:utf-8 import turtle as t t.screensize(400, 300, "blue") t.pensize(4) # 设置画笔的大小 t.colormode(255) # 设置GBK颜色范围为0-255 t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink) t.setup(840,500) # 设置主窗口的大小为840*500 t.speed(10) # 设置画笔速度

python画小猪佩奇

试验环境python3,不知python2能不能运行. 代码如下: # -*- coding:utf-8 -*-import turtle as tt.pensize(4) # 设置画笔的大小t.colormode(255) # 设置GBK颜色范围为0-255t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink)t.setup(840,500) # 设置主窗口的大小为840*500t.speed(10) # 设置画笔速度为10#鼻子t.pu(

小猪佩奇社会人专用服务器,有意思的python小程序,附python代码

最近社会人小猪佩奇挺热门的,大家都在说社会人,那么我们作为IT人,怎么让我们的服务器也蹭一下社会人的热点的?下面来给大家说说. 先来个效果图: 小猪佩奇社会人专用服务器 哈哈,这样是不是挺有意思的?工作已经很无聊了,如果再不找点乐趣,那还怎么干活? 说说怎么实现的吧,其实这个是通过python代码实现的,而且代码仅仅只有30行. 需要说明的是,这个python代码不仅仅能转换小猪佩奇社会人,而且还能转换各种图片,比如佛祖啊什么的,只要你有色彩对比度差不多的图片,都可以进行转换. 如下图,我换了个

如何用Python代码画小猪佩奇

Python语言的功能太强大了,可以制作出很多想想的作品来,不信吗?用Python代码还可以画出小猪佩奇,代码其实很简单的,下面,就将几个关键步骤代码分享出来. 怎么用Python代码画小猪佩奇? 首先需要初始化画笔的一些属性,包括颜色.画笔的画画速度等. def init_pen(): ''' 初始化画笔的一些属性 ''' t.pensize(4) # 设置画笔的大小 t.colormode(255) # 设置GBK颜色范围为0-255 t.color((255, 155, 192), "pi

*【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle import* def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东.90-北.180-西.270-南) begin_fill()#准备开始填充图形 a

使用canvas 代码画小猪佩奇

<canvas id="myCanvas" width="400" height="500" style="border: 1px solid #808080; margin-left:400px;" onmousemove="cnvs_getCoordinates(event);" onmouseout="cnvs_clearCoordinates();">看不见我!!!&

论“小猪佩奇如何从营销到吸金一路开挂前行”!

如果有人问我最喜欢的动画片是什么,我会毫不犹豫地回答--小猪佩奇.因为他们真是太可爱.太可爱了...关于这只来自英国的粉红色小猪,不仅人气超高,而且身价不菲,是最赚钱的动画人物之一.小猪佩奇为啥这么火?背后有着怎样的营销逻辑? 一.动画内容演绎现代家庭生活,引发共鸣! 小猪佩奇该动画从孩子的视野入手,当你去看小猪佩奇的动画片的时候,你会发现这个动画片的设定相当美好,简单的家庭生活,情节都是一幕幕平常生活中小孩子会真正遇到的事情,看片就像见证自己孩子的成长一样.而且故事没有像<喜羊羊与灰太狼>和

div+css画一个小猪佩奇

用DIV+CSS画一个小猪佩奇,挺可爱的,嘻嘻. HTML部分(全是DIV) <!-- 小猪佩奇整体容器 --> <div class="pig_container"> <!-- 尾巴 --> <div class="tail_left"></div> <div class="tail_right"></div> <div class="tail_