學習記錄,python
筆控制學習
turtle.
pendown
()字體
turtle.
pd
()code
turtle.
down
(),下筆,移動時繪畫。orm
turtle.
penup
()blog
turtle.
pu
()string
turtle.
up
(),拿起筆,移動時不繪畫。it
turtle.
pensize
(width=None)io
turtle.
width
(width=None),返回或者設置筆畫寬度。class
turtle.
pen
(pen=None, **pendict),設置筆的屬性。
「shown」: True/False
「pendown」: True/False
「pencolor」: color-string or color-tuple
「fillcolor」: color-string or color-tuple
「pensize」: positive number
「speed」: number in range 0..10
「resizemode」: 「auto」 or 「user」 or 「noresize」
「stretchfactor」: (positive number, positive number)
「outline」: positive number
「tilt」: number
turtle.
isdown
(),是否下筆,下筆返回True,提起筆False。
turtle.
fillcolor
(*args),返回或設置填充顏色。
能夠是,fillcolor(colorstring)像"violet","#33cc8c";fillcolor((r, g, b));fillcolor(r, g, b)。
配合begin_fill()和end_fill()使用。
運行到turtle.end_fill()填充。
turtle.
color
(*args),返回或設置筆的顏色和填充的顏色。
color(colorstring1, colorstring2)
, color((r1,g1,b1), (r2,g2,b2)),等效於pencolor(colorstring1)
和 fillcolor(colorstring2)
turtle.
filling
(),返回填充狀態,有設置開始填充返回True,不然返回False。
turtle.
begin_fill
(),開始填充位置。
turtle.
end_fill
(),結束填充位置。
turtle.
reset
(),重置,龜返回原點並清除已繪屏,
turtle.
clear
(),清除已繪屏,龜當前狀態和位置不變。
turtle.
write
(arg, move=False, align="left", font=("Arial", 8, "normal")),寫入文本。
arg要寫入的文本,move是否向右移動,align文本對齊,font字體大小,格式...元組。
試畫下簡單的圖;
import turtle as t t.home() #開始原點 t.fillcolor('violet') #填充顏色 t.penup() #拿起筆 t.begin_fill() #開始填充violet色 t.stamp() #當前位置複製龜圖形 t.fd(100) #向前移100 t.setheading(90) #設置指向角度90 t.stamp() t.fd(100) t.lt(90) #向左轉90度 t.end_fill() #結束填充 t.fillcolor('cyan') t.stamp() t.begin_fill() t.fd(100) t.lt(90) t.stamp() t.fd(100) t.end_fill() t.home() ##畫另外一個圖 t.setpos(0,-150) #移到座標0,-150 t.pendown() #放下筆開始繪 t.pencolor('violet') #設筆顏色 for i in range(0,24): t.forward(100) t.left(105) t.stamp()
如圖;