用Python画小女孩放风筝的示例

我就废话不多说了,直接上代码吧!

# coding:utf-8
 2import turtle as t
 3import random
 4# 画心
 5def xin():
 6  def curvemove():
 7    for i in range(200):
 8      t.right(1)
 9      t.forward(0.5)
 10  t.color('red','red')
 11  t.begin_fill()
 12  t.left(140)
 13  t.forward(60)
 14  curvemove()
 15  t.left(120)
 16  curvemove()
 17  t.forward(60)
 18  t.end_fill()
 19# 心里面的十字
 20def shizi():
 21  t.pu()
 22  t.goto(170,285)
 23  t.seth(0)
 24  t.pd()
 25  t.color("black","black")
 26  t.circle(1.5)
 27  t.pensize(2)
 28  t.fd(55)
 29  t.pensize(4)
 30  t.circle(1.5)
 31  t.pu()
 32  t.seth(-90)
 33  t.goto(198,295)
 34  t.seth(-90)
 35  t.pensize(2)
 36  t.pd()
 37  t.fd(65)
 38  t.circle(1.5)
 39  t.circle(160,40)
 40  t.circle(-130,27)
 41  t.circle(-60,40)
 42  t.circle(80,60)
 43# 夹子
 44def jiazi2():
 45  def jiazi(angle):
 46    t.pd()
 47    t.pensize(1)
 48    t.color("black","brown")
 49    t.begin_fill()
 50    t.seth(angle)
 51    t.fd(20)
 52    t.seth(angle-240)
 53    t.fd(10)
 54    t.seth(angle-120)
 55    t.fd(20)
 56    t.seth(angle-240)
 57    t.fd(10)
 58    t.end_fill()
 59    t.pu()
 60  # 画夹子
 61  t.pu()
 62  t.goto(216,180)
 63  jiazi(180)
 64  t.goto(230,150)
 65  jiazi(200)
 66  t.goto(250,125)
 67  jiazi(220)
 68  t.goto(265,95)
 69  jiazi(200)
 70  t.goto(275,55)
 71  jiazi(160)
 72# 人
 73def people():
 74  t.pensize(2)
 75  # 皇冠
 76  def huangguan():
 77    t.pu()
 78    t.goto(-200,0)
 79    t.color("gold","gold")
 80    t.pd()
 81    t.begin_fill()
 82    t.seth(120)
 83    t.fd(32)
 84    t.seth(-120)
 85    t.fd(15)
 86    t.seth(150)
 87    t.fd(10)
 88    t.seth(-120)
 89    t.fd(10)
 90    t.seth(160)
 91    t.fd(15)
 92    t.seth(-60)
 93    t.fd(32)
 94    t.seth(50)
 95    t.circle(-40,60)
 96    t.end_fill()
 97  # 脸
 98  def face():
 99    t.pu()
100    t.goto(-212,-3)
101    t.color("black","white")
102    t.pd()
103    t.circle(-40,150)
104  # 头发
105  def hair():
106    t.pu()
107    t.color("black","black")
108    t.goto(-212, -3)
109    angle = -160
110    for i in range(32):
111      t.pd()
112      angle += 1.4
113      t.seth(angle)
114      t.circle(60, 50)
115      t.fd(random.randint(40,45))
116      t.pu()
117      t.goto(-212, -3)
118    angle = -50
119    for i in range(32):
120      t.pd()
121      angle -= 1.5
122      t.seth(angle)
123      t.circle(-60, 50)
124      t.fd(random.randint(38,40))
125      t.pu()
126      t.goto(-212, -5)
127  # 脖子
128  def nick():
129    t.pu()
130    t.goto(-200,-78)
131    t.pd()
132    t.seth(-90)
133    t.fd(10)
134    t.seth(-45)
135    t.fd(20)
136    t.seth(180)
137    t.fd(30)
138    t.seth(55)
139    t.fd(15)
140    t.circle(10,80)
141  # 下半身
142  def body():
143    t.pu()
144    t.goto(-185,-100)
145    t.seth(-65)
146    t.pd()
147    for i in range(120):
148      t.fd(1.5)
149      t.right(0.1)
150    t.seth(220)
151    t.circle(-130,70)
152    t.seth(75)
153    for i in range(130):
154      t.fd(1.5)
155      t.right(0.06)
156  # 腿
157  def leg():
158    t.pu()
159    t.goto(-220,-300)
160    t.pd()
161    t.seth(-90)
162    t.fd(80)
163    t.pensize(5)
164    t.color("red","red")
165    t.fd(8)
166    t.seth(-30)
167    t.pensize(6)
168    t.color("black","black")
169    t.fd(5)
170    t.pu()
171    t.pensize(2)
172    t.goto(-185,-300)
173    t.pd()
174    t.seth(-90)
175    t.fd(80)
176    t.pensize(5)
177    t.color("red","red")
178    t.fd(8)
179    t.seth(-30)
180    t.pensize(6)
181    t.color("black","black")
182    t.fd(5)
183  huangguan()
184  face()
185  nick()
186  body()
187  leg()
188  hair()
189  # 手
190  t.pu()
191  t.goto(-190,-165)
192  t.pensize(2)
193  t.pd()
194  t.seth(49)
195  t.fd(160)
196  t.circle(-10,80)
197  # 眼睛
198  t.pu()
199  t.goto(-185,-30)
200  t.seth(90)
201  t.pd()
202  t.circle(5,180)
203# 星星
204def star(x,y):
205  color = ["blue","yellow","red","gold","orange","pink","green","purple"]
206  t.pencolor(random.choice(color))
207  t.pu()
208  t.goto(x,y)
209  t.pd()
210  t.seth(90)
211  t.fd(8)
212  t.bk(4)
213  t.seth(0)
214  t.fd(4)
215  t.bk(8)
216  t.fd(4)
217  t.seth(45)
218  t.fd(4)
219  t.bk(8)
220  t.fd(4)
221  t.seth(-45)
222  t.fd(4)
223  t.bk(8)
224if __name__ == "__main__":
225  t.pensize(4) # 设置画笔的大小
226  t.color("black") # 设置画笔颜色和填充颜色(pink)
227  t.setup(650, 800) # 设置主窗口的大小为600*800
228  t.speed(10) # 设置画笔速度为10
229  t.pu()
230  t.goto(200, 220)
231  t.pd()
232  # 心
233  xin()
234  # 十字
235  shizi()
236  # 夹子
237  jiazi2()
238  #线
239  t.pu()
240  t.goto(198,280)
241  t.pd()
242  t.seth(-120)
243  t.circle(-1100,22)
244  t.circle(20,90)
245  t.circle(-30,50)
246  t.circle(15,60)
247  # 人
248  people()
249  # 裙子上的点点
250  star(-230, -200)
251  star(-220, -180)
252  star(-200, -150)
253  star(-180, -288)
254  star(-160, -250)
255  star(-210, -150)
256  star(-210, -140)
257  for i in range(10):
258    star(random.randint(-205,-170),random.randint(-300,-200))
259  # 隐藏画笔
260  t.ht()
261  t.done()

效果如下:

以上这篇用Python画小女孩放风筝的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • 使用python画个小猪佩奇的示例代码

    基本原理 选好画板大小,设置好画笔颜色.粗细,定位好位置,依次画鼻子.头.耳朵.眼睛.腮.嘴.身体.手脚.尾巴,完事儿. 都知道,Turtle 是 Python 内置的一个比较有趣味的模块,俗称"海龟绘图",它是基于 Tkinter 模块打造,提供一些简单的绘图工具. 在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动.这个海龟带着一只钢笔,我们可以让海龟无论移动到哪都使用这只钢笔来绘制线条.通过编写代码,以各种很酷的模式移动海龟,我们可以绘制出令人惊奇的图片.

  • 使用Python画出小人发射爱心的代码

    我就废话不多说了,直接上代码吧! #2.14 from turtle import * from time import sleep def go_to(x, y): up() goto(x, y) down() def head(x,y,r): go_to(x,y) speed(1) circle(r) leg(x,y) def leg(x,y): right(90) forward(180) right(30) forward(100) left(120) go_to(x,y-180) fo

  • 使用python的turtle绘画滑稽脸实例

    这是借鉴了一位兄弟的代码,然后进行修改的,原来代码存在问题,用了2小时,自己修改,终于画出了滑稽脸,也算是对于今天学的turtle绘画库的一个小小的记录吧!(有错误希望各位看官指正啊) 编译器是:Atom python 是3.7版本 运行位 Windows power shell import turtle turtle.setup(600,600,200,200) #fcae turtle.penup() turtle.goto(-210,0) turtle.seth(-90) turtle.

  • 教你使用python画一朵花送女朋友

    本文实例为大家分享了用python画一朵花的具体代码,供大家参考,具体内容如下 第一种,画法 from turtle import * import time setup(600,800,0,0) speed(0) penup() seth(90) fd(340) seth(0) pendown() speed(5) begin_fill() fillcolor('red') circle(50,30) for i in range(10): fd(1) left(10) circle(40,4

  • 用Python画小女孩放风筝的示例

    我就废话不多说了,直接上代码吧! # coding:utf-8 2import turtle as t 3import random 4# 画心 5def xin(): 6 def curvemove(): 7 for i in range(200): 8 t.right(1) 9 t.forward(0.5) 10 t.color('red','red') 11 t.begin_fill() 12 t.left(140) 13 t.forward(60) 14 curvemove() 15 t

  • python画双y轴图像的示例代码

    很多时候可能需要在一个图中画出多条函数图像,但是可能y轴的物理含义不一样,或是数值范围相差较大,此时就需要双y轴. matplotlib和seaborn都可以画双y轴图像. 一个例子: import seaborn as sns import matplotlib.pyplot as plt # ax1 for KDE, ax2 for CDF f, ax1 = plt.subplots() ax1.grid(True) # ax1.set_ylim(0, 1) ax1.set_ylabel('

  • python 画三维图像 曲面图和散点图的示例

    用python画图很多是根据z=f(x,y)来画图的,本博文将三个对应的坐标点输入画图: 散点图: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() ax = fig.add_subplot(111, projection='3d') X = [1, 1, 2, 2] Y = [3, 4, 4, 3] Z = [1, 2, 1, 1] ax.scatter(X, Y

  • python 画函数曲线示例

    如下所示: import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 100) y1, y2 = np.sin(x), np.cos(x) plt.plot(x, y1) plt.plot(x, y2) plt.title('line chart') plt.xlabel('x') plt.ylabel('y') plt.show() 以上这篇python 画函数曲线示例就是小编分享给大家的全

  • 用Python画圣诞树代码示例

    拿去给自己所思所念之人 from turtle import * import time setup(500, 500, startx=None, starty=None) speed(0) pencolor("pink") pensize(10) penup() hideturtle() goto(0, 150) showturtle() pendown() shape(name="classic") # 1 seth(-120) for i in range(1

  • 用python画圣诞树三种代码示例介绍

    目录 前言 1.方块圣诞树 2.线条圣诞树 3.豪华圣诞树 总结 前言 这篇文章主要介绍了使用Python画了一棵圣诞树的实例代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下 如何用python画一个圣诞树呢? Turtle库来画圣诞树. 1.方块圣诞树 import turtle screen = turtle.Screen() screen.setup(375, 700) circle = turtle.Turtle() circle

  • Python画柱状统计图操作示例【基于matplotlib库】

    本文实例讲述了Python画柱状统计图操作.分享给大家供大家参考,具体如下: 一.工具:python的matplotlib.pyplot 库 二.案例: import matplotlib.pyplot as plt import numpy as np #添加图形属性 plt.xlabel('Age range') plt.ylabel('Number') plt.title('The statistics of face age dataset') a = plt.subplot(1, 1,

  • python 画二维、三维点之间的线段实现方法

    如下所示: from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt # 打开画图窗口1,在三维空间中绘图 fig = plt.figure(1) ax = fig.gca(projection='3d') # 给出点(0,0,0)和(100,200,300) x = [0, 100] y = [0, 200] z = [0, 300] # 将数组中的前两个点进行连线 figure = ax.plot(x, y

随机推荐