Python庫-----Turtle繪圖庫


https://www.cnblogs.com/bravestarrhu/p/8287261.html

https://blog.csdn.net/zengxiantao1994/article/details/76588580

 

Turtle庫是Python語言中一個很流行的繪制圖像的函數庫,想象一個小烏龜,在一個橫軸為x、縱軸為y的坐標系原點,(0,0)位置開始,它根據一組函數指令的控制,在這個平面坐標系中移動,從而在它爬行的路徑上繪制了圖形。

turtle繪圖的基礎知識:

1. 畫布(canvas)

        畫布就是turtle為我們展開用於繪圖區域,我們可以設置它的大小和初始位置。

        設置畫布大小

         turtle.screensize(canvwidth=None, canvheight=None, bg=None),參數分別為畫布的寬(單位像素), 高, 背景顏色。

        如:turtle.screensize(800,600, "green")

               turtle.screensize() #返回默認大小(400, 300)

        turtle.setup(width=0.5, height=0.75, startx=None, starty=None),參數:width, height: 輸入寬和高為整數時, 表示像素; 為小數時, 表示占據電腦屏幕的比例,(startx, starty): 這一坐標表示矩形窗口左上角頂點的位置, 如果為空,則窗口位於屏幕中心。

        如:turtle.setup(width=0.6,height=0.6)

               turtle.setup(width=800,height=800, startx=100, starty=100)

 

2. 畫筆

2.1 畫筆的狀態

        在畫布上,默認有一個坐標原點為畫布中心的坐標軸,坐標原點上有一只面朝x軸正方向小烏龜。這里我們描述小烏龜時使用了兩個詞語:坐標原點(位置),面朝x軸正方向(方向), turtle繪圖中,就是使用位置方向描述小烏龜(畫筆)的狀態。

2.2 畫筆的屬性

        畫筆(畫筆的屬性,顏色、畫線的寬度等)

        1) turtle.pensize():設置畫筆的寬度;

        2) turtle.pencolor():沒有參數傳入,返回當前畫筆顏色,傳入參數設置畫筆顏色,可以是字符串如"green", "red",也可以是RGB 3元組。

        3) turtle.speed(speed):設置畫筆移動速度,畫筆繪制的速度范圍[0,10]整數,數字越大越快。

2.3 繪圖命令

         操縱海龜繪圖有着許多的命令,這些命令可以划分為3種:一種為運動命令,一種為畫筆控制命令,還有一種是全局控制命令。

(1)    畫筆運動命令

命令

說明

turtle.forward(distance) 

 
| turtle.fd(distance)

向當前畫筆方向移動distance像素長度

turtle.backward(distance)

| turtle.back(distance) | turtle.bk(distance)

向當前畫筆相反方向移動distance像素長度

turtle.right(degree)

| turtle.rt(angle)

順時針移動degree°

turtle.left(degree)

| turtle.lt(angle)

逆時針移動degree°

turtle.pendown()

移動時繪制圖形,缺省時也為繪制

turtle.goto(x,y)

將畫筆移動到坐標為x,y的位置

turtle.penup()

提起筆移動,不繪制圖形,用於另起一個地方繪制

turtle.circle()

畫圓,半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓

setx( )

將當前x軸移動到指定位置

sety( )

將當前y軸移動到指定位置

setheading(angle)

turtle.seth(to_angle)

設置當前朝向為angle角度

home()

設置當前畫筆位置為原點,朝向東。

dot(r)

繪制一個指定直徑和顏色的圓點

 

(2)     畫筆控制命令

命令

說明

turtle.fillcolor(colorstring)

繪制圖形的填充顏色

turtle.color(color1, color2)

同時設置pencolor=color1, fillcolor=color2

turtle.filling()

返回當前是否在填充狀態

turtle.begin_fill()

准備開始填充圖形

turtle.end_fill()

填充完成

turtle.hideturtle()

隱藏畫筆的turtle形狀

turtle.showturtle()

顯示畫筆的turtle形狀

 

(3)    全局控制命令

命令

說明

turtle.clear()

清空turtle窗口,但是turtle的位置和狀態不會改變

turtle.reset()

清空窗口,重置turtle狀態為起始狀態

turtle.undo()

撤銷上一個turtle動作

turtle.isvisible()

返回當前turtle是否可見

stamp()

復制當前圖形

turtle.write(s [,font=("font-name",font_size,"font_type")])

寫文本,s為文本內容,font是字體的參數,分別為字體名稱,大小和類型;font為可選項,font參數也是可選項

 

(4)    其他命令

命令

說明

turtle.mainloop()或turtle.done()

啟動事件循環 -調用Tkinter的mainloop函數。

必須是烏龜圖形程序中的最后一個語句。

turtle.mode(mode=None)

設置烏龜模式(“standard”,“logo”或“world”)並執行重置。如果沒有給出模式,則返回當前模式。

模式

初始龜標題

正角度

standard

向右(東)

逆時針

logo

向上(北)

順時針

turtle.delay(delay=None)

設置或返回以毫秒為單位的繪圖延遲。

turtle.begin_poly()

開始記錄多邊形的頂點。當前的烏龜位置是多邊形的第一個頂點。

turtle.end_poly()

停止記錄多邊形的頂點。當前的烏龜位置是多邊形的最后一個頂點。將與第一個頂點相連。

turtle.get_poly()

返回最后記錄的多邊形。

 

3. 命令詳解

        3.1 turtle.circle(radius, extent=None, steps=None)

        描述:以給定半徑畫圓

        參數:

        radius(半徑):半徑為正(負),表示圓心在畫筆的左邊(右邊)畫圓;

        extent(弧度) (optional);

        steps (optional) (做半徑為radius的圓的內切正多邊形,多邊形邊數為steps)。

舉例:

circle(50) # 整圓;

circle(50,steps=3) # 三角形;

circle(120, 180) # 半圓

 

實例:

 1 # coding=utf-8
 2 import turtle
 3 import time
 4  
 5 # 同時設置pencolor=color1, fillcolor=color2
 6 turtle.color("red", "yellow")
 7  
 8 turtle.begin_fill()
 9 for _ in range(50):
10     turtle.forward(200)
11     turtle.left(170)
12 turtle.end_fill()
13  
14 turtle.mainloop()
太陽花

 

 1 # coding=utf-8
 2 import turtle
 3 import time
 4  
 5 turtle.pensize(5)
 6 turtle.pencolor("yellow")
 7 turtle.fillcolor("red")
 8  
 9 turtle.begin_fill()
10 for _ in range(5):
11   turtle.forward(200)
12   turtle.right(144)
13 turtle.end_fill()
14 time.sleep(2)
15  
16 turtle.penup()
17 turtle.goto(-150,-120)
18 turtle.color("violet")
19 turtle.write("Done", font=('Arial', 40, 'normal'))
20  
21 turtle.mainloop()
五角星

 

  1 # coding=utf-8
  2  
  3 import turtle
  4 from datetime import *
  5  
  6 # 抬起畫筆,向前運動一段距離放下
  7 def Skip(step):
  8     turtle.penup()
  9     turtle.forward(step)
 10     turtle.pendown()
 11  
 12 def mkHand(name, length):
 13     # 注冊Turtle形狀,建立表針Turtle
 14     turtle.reset()
 15     Skip(-length * 0.1)
 16     # 開始記錄多邊形的頂點。當前的烏龜位置是多邊形的第一個頂點。
 17     turtle.begin_poly()
 18     turtle.forward(length * 1.1)
 19     # 停止記錄多邊形的頂點。當前的烏龜位置是多邊形的最后一個頂點。將與第一個頂點相連。
 20     turtle.end_poly()
 21     # 返回最后記錄的多邊形。
 22     handForm = turtle.get_poly()
 23     turtle.register_shape(name, handForm)
 24  
 25 def Init():
 26     global secHand, minHand, hurHand, printer
 27     # 重置Turtle指向北
 28     turtle.mode("logo")
 29     # 建立三個表針Turtle並初始化
 30     mkHand("secHand", 135)
 31     mkHand("minHand", 125)
 32     mkHand("hurHand", 90)
 33     secHand = turtle.Turtle()
 34     secHand.shape("secHand")
 35     minHand = turtle.Turtle()
 36     minHand.shape("minHand")
 37     hurHand = turtle.Turtle()
 38     hurHand.shape("hurHand")
 39    
 40     for hand in secHand, minHand, hurHand:
 41         hand.shapesize(1, 1, 3)
 42         hand.speed(0)
 43    
 44     # 建立輸出文字Turtle
 45     printer = turtle.Turtle()
 46     # 隱藏畫筆的turtle形狀
 47     printer.hideturtle()
 48     printer.penup()
 49     
 50 def SetupClock(radius):
 51     # 建立表的外框
 52     turtle.reset()
 53     turtle.pensize(7)
 54     for i in range(60):
 55         Skip(radius)
 56         if i % 5 == 0:
 57             turtle.forward(20)
 58             Skip(-radius - 20)
 59            
 60             Skip(radius + 20)
 61             if i == 0:
 62                 turtle.write(int(12), align="center", font=("Courier", 14, "bold"))
 63             elif i == 30:
 64                 Skip(25)
 65                 turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
 66                 Skip(-25)
 67             elif (i == 25 or i == 35):
 68                 Skip(20)
 69                 turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
 70                 Skip(-20)
 71             else:
 72                 turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
 73             Skip(-radius - 20)
 74         else:
 75             turtle.dot(5)
 76             Skip(-radius)
 77         turtle.right(6)
 78         
 79 def Week(t):   
 80     week = ["星期一", "星期二", "星期三",
 81             "星期四", "星期五", "星期六", "星期日"]
 82     return week[t.weekday()]
 83  
 84 def Date(t):
 85     y = t.year
 86     m = t.month
 87     d = t.day
 88     return "%s %d%d" % (y, m, d)
 89  
 90 def Tick():
 91     # 繪制表針的動態顯示
 92     t = datetime.today()
 93     second = t.second + t.microsecond * 0.000001
 94     minute = t.minute + second / 60.0
 95     hour = t.hour + minute / 60.0
 96     secHand.setheading(6 * second)
 97     minHand.setheading(6 * minute)
 98     hurHand.setheading(30 * hour)
 99     
100     turtle.tracer(False) 
101     printer.forward(65)
102     printer.write(Week(t), align="center",
103                   font=("Courier", 14, "bold"))
104     printer.back(130)
105     printer.write(Date(t), align="center",
106                   font=("Courier", 14, "bold"))
107     printer.home()
108     turtle.tracer(True)
109  
110     # 100ms后繼續調用tick
111     turtle.ontimer(Tick, 100)
112  
113 def main():
114     # 打開/關閉龜動畫,並為更新圖紙設置延遲。
115     turtle.tracer(False)
116     Init()
117     SetupClock(160)
118     turtle.tracer(True)
119     Tick()
120     turtle.mainloop()
121  
122 if __name__ == "__main__":
123     main()
時鍾

 

  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()#畫筆抬起 penup
 12 t.goto(-100,100)
 13 t.pd()#畫筆按下 pendown
 14 t.seth(-30)#設置方向在逆時針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)   #left 繪制方向向左旋轉angle度
 21         t.fd(a)   #forward 畫筆向繪制方向的當前方向移動的pixels距離
 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)
 78         t.fd(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((255,99,71),"red")
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 
274 #尾巴
275 t.pensize(4)
276 t.color((255,155,192))
277 t.pu()
278 t.seth(90)
279 t.fd(70)
280 t.seth(0)
281 t.fd(95)
282 t.pd()
283 t.seth(0)
284 t.circle(70,20)
285 t.circle(10,330)
286 t.circle(70,30)
287 t.done()
小豬佩奇

  1 # !/usr/bin/env python3
  2 
  3 # -*- coding: utf-8 -*-
  4 
  5 
  6 
  7 # @Env: python 3.6
  8 
  9 
 10 
 11 from turtle import *
 12 
 13 
 14 
 15 # 無軌跡跳躍
 16 
 17 def my_goto(x, y):
 18 
 19     penup()
 20 
 21     goto(x, y)
 22 
 23     pendown()
 24 
 25 
 26 # 眼睛
 27 
 28 def eyes():
 29 
 30     tracer(False)
 31 
 32     a = 2.5
 33 
 34     for i in range(120):
 35 
 36         if 0 <= i < 30 or 60 <= i < 90:
 37 
 38             a -= 0.05
 39 
 40             lt(3)
 41 
 42             fd(a)
 43 
 44         else:
 45 
 46             a += 0.05
 47 
 48             lt(3)
 49 
 50             fd(a)
 51 
 52     tracer(True)
 53 
 54 
 55 # 胡須
 56 
 57 def beard():
 58 
 59     my_goto(-37, 135)
 60 
 61     seth(165)
 62 
 63     fd(60)
 64 
 65 
 66     my_goto(-37, 125)
 67 
 68     seth(180)
 69 
 70     fd(60)
 71 
 72 
 73     my_goto(-37, 115)
 74 
 75     seth(193)
 76 
 77     fd(60)
 78 
 79 
 80     my_goto(37, 135)
 81 
 82     seth(15)
 83 
 84     fd(60)
 85 
 86 
 87     my_goto(37, 125)
 88 
 89     seth(0)
 90 
 91     fd(60)
 92 
 93 
 94     my_goto(37, 115)
 95 
 96     seth(-13)
 97 
 98     fd(60)
 99 
100 
101 # 嘴巴
102 
103 def mouth():
104 
105     my_goto(5, 148)
106 
107     seth(270)
108 
109     fd(100)
110 
111     seth(0)
112 
113     circle(120, 50)
114 
115     seth(230)
116 
117     circle(-120, 100)
118 
119 
120 # 圍巾
121 
122 def scarf():
123 
124     fillcolor('#e70010')
125 
126     begin_fill()
127 
128     seth(0)
129 
130     fd(200)
131 
132     circle(-5, 90)
133 
134     fd(10)
135 
136     circle(-5, 90)
137 
138     fd(207)
139 
140     circle(-5, 90)
141 
142     fd(10)
143 
144     circle(-5, 90)
145 
146     end_fill()
147 
148 
149 # 鼻子
150 
151 def nose():
152 
153     my_goto(-10, 158)
154 
155     fillcolor('#e70010')
156 
157     begin_fill()
158 
159     circle(20)
160 
161     end_fill()
162 
163 
164 # 黑眼睛
165 
166 def black_eyes():
167 
168     seth(0)
169 
170     my_goto(-20, 195)
171 
172     fillcolor('#000000')
173 
174     begin_fill()
175 
176     circle(13)
177 
178     end_fill()
179 
180 
181     pensize(6)
182 
183     my_goto(20, 205)
184 
185     seth(75)
186 
187     circle(-10, 150)
188 
189     pensize(3)
190 
191 
192     my_goto(-17, 200)
193 
194     seth(0)
195 
196     fillcolor('#ffffff')
197 
198     begin_fill()
199 
200     circle(5)
201 
202     end_fill()
203 
204     my_goto(0, 0)
205 
206 
207 
208 
209 #
210 
211 def face():
212 
213     fd(183)
214 
215     fillcolor('#ffffff')
216 
217     begin_fill()
218 
219     lt(45)
220 
221     circle(120, 100)
222 
223 
224     seth(90)
225 
226     eyes()
227 
228     seth(180)
229 
230     penup()
231 
232     fd(60)
233 
234     pendown()
235 
236     seth(90)
237 
238     eyes()
239 
240     penup()
241 
242     seth(180)
243 
244     fd(64)
245 
246     pendown()
247 
248     seth(215)
249 
250     circle(120, 100)
251 
252     end_fill()
253 
254 
255 # 頭型
256 
257 def head():
258 
259     penup()
260 
261     circle(150, 40)
262 
263     pendown()
264 
265     fillcolor('#00a0de')
266 
267     begin_fill()
268 
269     circle(150, 280)
270 
271     end_fill()
272 
273 
274 # 畫哆啦A夢
275 
276 def Doraemon():
277 
278     # 頭部
279 
280     head()
281 
282 
283     # 圍脖
284 
285     scarf()
286 
287 
288     #
289 
290     face()
291 
292 
293     # 紅鼻子
294 
295     nose()
296 
297 
298     # 嘴巴
299 
300     mouth()
301 
302 
303     # 胡須
304 
305     beard()
306 
307 
308     # 身體
309 
310     my_goto(0, 0)
311 
312     seth(0)
313 
314     penup()
315 
316     circle(150, 50)
317 
318     pendown()
319 
320     seth(30)
321 
322     fd(40)
323 
324     seth(70)
325 
326     circle(-30, 270)
327 
328 
329 
330     fillcolor('#00a0de')
331 
332     begin_fill()
333 
334 
335     seth(230)
336 
337     fd(80)
338 
339     seth(90)
340 
341     circle(1000, 1)
342 
343     seth(-89)
344 
345     circle(-1000, 10)
346 
347 
348     # print(pos())
349 
350 
351     seth(180)
352 
353     fd(70)
354 
355     seth(90)
356 
357     circle(30, 180)
358 
359     seth(180)
360 
361     fd(70)
362 
363 
364     # print(pos())
365 
366     seth(100)
367 
368     circle(-1000, 9)
369 
370 
371     seth(-86)
372 
373     circle(1000, 2)
374 
375     seth(230)
376 
377     fd(40)
378 
379 
380     # print(pos())
381 
382 
383 
384     circle(-30, 230)
385 
386     seth(45)
387 
388     fd(81)
389 
390     seth(0)
391 
392     fd(203)
393 
394     circle(5, 90)
395 
396     fd(10)
397 
398     circle(5, 90)
399 
400     fd(7)
401 
402     seth(40)
403 
404     circle(150, 10)
405 
406     seth(30)
407 
408     fd(40)
409 
410     end_fill()
411 
412 
413     # 左手
414 
415     seth(70)
416 
417     fillcolor('#ffffff')
418 
419     begin_fill()
420 
421     circle(-30)
422 
423     end_fill()
424 
425 
426     #
427 
428     my_goto(103.74, -182.59)
429 
430     seth(0)
431 
432     fillcolor('#ffffff')
433 
434     begin_fill()
435 
436     fd(15)
437 
438     circle(-15, 180)
439 
440     fd(90)
441 
442     circle(-15, 180)
443 
444     fd(10)
445 
446     end_fill()
447 
448 
449     my_goto(-96.26, -182.59)
450 
451     seth(180)
452 
453     fillcolor('#ffffff')
454 
455     begin_fill()
456 
457     fd(15)
458 
459     circle(15, 180)
460 
461     fd(90)
462 
463     circle(15, 180)
464 
465     fd(10)
466 
467     end_fill()
468 
469 
470     # 右手
471 
472     my_goto(-133.97, -91.81)
473 
474     seth(50)
475 
476     fillcolor('#ffffff')
477 
478     begin_fill()
479 
480     circle(30)
481 
482     end_fill()
483 
484 
485     # 口袋
486 
487     my_goto(-103.42, 15.09)
488 
489     seth(0)
490 
491     fd(38)
492 
493     seth(230)
494 
495     begin_fill()
496 
497     circle(90, 260)
498 
499     end_fill()
500 
501 
502     my_goto(5, -40)
503 
504     seth(0)
505 
506     fd(70)
507 
508     seth(-90)
509 
510     circle(-70, 180)
511 
512     seth(0)
513 
514     fd(70)
515 
516 
517     #鈴鐺
518 
519     my_goto(-103.42, 15.09)
520 
521     fd(90)
522 
523     seth(70)
524 
525     fillcolor('#ffd200')
526 
527     # print(pos())
528 
529     begin_fill()
530 
531     circle(-20)
532 
533     end_fill()
534 
535     seth(170)
536 
537     fillcolor('#ffd200')
538 
539     begin_fill()
540 
541     circle(-2, 180)
542 
543     seth(10)
544 
545     circle(-100, 22)
546 
547     circle(-2, 180)
548 
549     seth(180-10)
550 
551     circle(100, 22)
552 
553     end_fill()
554 
555     goto(-13.42, 15.09)
556 
557     seth(250)
558 
559     circle(20, 110)
560 
561     seth(90)
562 
563     fd(15)
564 
565     dot(10)
566 
567     my_goto(0, -150)
568 
569 
570     # 畫眼睛
571 
572     black_eyes()
573 
574 
575 if __name__ == '__main__':
576 
577     screensize(800,600, "#f0f0f0")
578 
579     pensize(3)  # 畫筆寬度
580 
581     speed(9)    # 畫筆速度
582 
583     Doraemon()
584 
585     my_goto(100, -300)
586 
587     # write('by dongdong', font=("Bradley Hand ITC", 30, "bold"))
588 
589     mainloop()
機器貓

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM