python画图

技术分享4年前 (2020)更新 技术分享
2,543 0 0

1.使用Python画图首先要有turtle库,请自行安装

2.首先我们先来画一个简单的等边三角形

 1 import turtle
 2 turtle.pensize(10)#笔画大小
 3 turtle.pencolor('red')#红色
 4 #画个等边三角形
 5  turtle.forward(100)
 6  turtle.right(120)
 7  turtle.forward(100)
 8  turtle.right(120)
 9  turtle.forward(100)
10 turtle.done()

python画图

 

3.类似的我们再来画一个五角星

 1 import turtle
 2 turtle.pensize(10)#笔画大小
 3 turtle.pencolor('red')#红色
 4 
 5 #画个五角星
 6 turtle.forward(200)
 7 turtle.right(144)
 8 turtle.forward(200)
 9 turtle.right(144)
10 turtle.forward(200)
11 turtle.right(144)
12 turtle.forward(200)
13 turtle.right(144)
14 turtle.forward(200)
15 
16 turtle.done()
17 #打印

python画图

 

 4.当然啦我们还可以创造出一颗小爱心

python画图

 1 import turtle
 2 def curvemove():
 3     for i in range(200):
 4         turtle.right(1)
 5         turtle.forward(1)
 6 turtle.color('red','pink')
 7 turtle.left(140)
 8 turtle.forward(111.65)
 9 curvemove()
10 turtle.left(120)
11 curvemove()
12 turtle.forward(111.65)
13 turtle.done()

View Code

python画图

 

 5.甚至可以画出一个小猪佩奇

python画图

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

View Code

python画图

 

 加油

 

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...