1. 程式人生 > >Python turtle庫

Python turtle庫

 turtle.setup(width,height,startx,starty)

 此函式用來設定視窗的大小及位置

其中 startx,starty兩個可選可不選,不選的話預設會在螢幕的正中間。

startx,starty是以螢幕左上角為原點建立的座標系中的位置。

width,height是視窗的寬度和高度。

turtle.goto(x,y)

去以視窗建立的直角座標系的x,y位置。

turtle.bk(d) 畫筆前進d畫素

tutle.fd(d) 畫筆後退d畫素

turtle.seth(angle) 畫筆旋轉angle度,改變畫筆的行進方向,但是不行進

turtle.left(angle)/right(angle) 畫筆向左/向右angle角度

turtle.colormode(mode) 設定RGB的模式

(1) 1.0-RGB小數值模式

(2) 255-RGB整數模式

turtle.circle(r,angle): 根據半徑r繪製angle角度的弧形,r預設圓心在畫筆左側r距離的位置 

turtle.penup() 擡起畫筆,海龜在飛行   別名 turtle.pu()

turtle.pendown() 落下畫筆,海龜在爬行  別名 turtle.pd()

turtle.pensize(width) 畫筆寬度,海龜腰圍   別名 turtle.width(width)

turtle.pencolor(color) color為顏色字串或r,g,b的值,畫筆顏色,海龜在塗裝

(1) 顏色字串 turtle.pencolor("red")

(2) RGB 的小數值 turtle.pencolor(0.63,0.13,0.94)

(3)RGB 的元組值 turtle.pencolor((0.63,0.13,0.94))

turtle.done(手動退出)