turtle庫基本使用


import turtle as t

畫筆控制函數:

t.penup()  抬起筆  別名:t.pu()

t.pendown()  落下筆  別名: t.pd()

t.pensize(2) 設置畫筆粗細   別名:t.width(width)

Example:
>>> pensize()
1
>>> pensize(10) # from here on lines of width 10 are drawn

t.pencolor(color)  畫筆顏色  color是顏色字符串或rgb值  color有3種形式:顏色字符串  t.pencolor('purple')     rgb小數值,rgb元組值 t.pencolor(0.1,0.5,1)   t.pencolor((0.1,0.5,1))

 

t.color('red','red)  設置畫筆顏色和填充顏色

Example:
>>> color('red', 'green')
>>> color()
('red', 'green')
>>> colormode(255)
>>> color((40, 80, 120), (160, 200, 240))
>>> color()
('#285078', '#a0c8f0')

 

t.begin_fill()  在繪制要填充的形狀之前調用。t.end_fill() 填充調用begin_fill()后繪制的形狀

Example:
>>> color("black", "red")
>>> begin_fill()
>>> circle(60)
>>> end_fill()

 

 

運動控制函數

t.fd(100)  向前走100像素

t.bk(40)  后退

t.circle(10)   圓心在海龜左側10像素的圓

circle(radius, extent=None, steps=None)  半徑,角度,邊數
Draw a circle with given radius.

>>> t.circle(50,360,6)
>>> t.circle(50,180,6)
>>> t.circle(50,180,6)

 

 方向控制函數

t.seth(-40)   行進方向角度的絕對坐標

t.left(30)   基於當前角度向左轉30度

t.right(20) 基於當前角度向右轉20度

 


免責聲明!

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



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