import turtle as t t.color('red') #填色選擇 t.begin_fill() #填色起點 t.end_fill() #填色終點 t.up() #提起筆, 代表不會描繪出邊框 t.goto(100,50) #游標移動到座標(100,50) t.down() #放下筆, 代表會描繪出邊框 t.circle(50) #從筆的位置畫出半徑為50的圓(注意:不是從圓心用圓規畫圓的概念)
# 範例5-1-5 畫紅色正方形 import turtle as t t.pen() t.color('red') t.begin_fill() #填色起點 for i in range(4): t.forward(200) t.left(90) t.end_fill() #填色終點 t.done()
# 範例5-1-5-1 畫正三角角 import turtle as t t.fillcolor("red") t.begin_fill() t.lt(240) t.fd(100) t.lt(120) t.fd(100) t.lt(120) t.fd(100) t.end_fill() t.done()
# 範例5-1-6 移動位置畫紅色正方形 import turtle as t t.up() t.goto(100,100) t.Pen() # t.down() t.color('red') t.begin_fill() #填色起點 for i in range(4): t.forward(200) t.left(90) t.end_fill() #填色終點 t.done()
# 範例5-1-7 移動位置畫兩個圓 import turtle as t t.goto(100,100) t.Pen() t.color('red') t.circle(100) t.circle(50) t.done()
# 範例5-1-8 試試預測會出現什麼圖案 import turtle as t t.up() t.goto(100,100) t.Pen() t.down() t.color('green') t.begin_fill() t.circle(50) t.color('red') t.circle(100) t.end_fill() t.done()
5-1-3-1 Case Study個案研究 : 螺旋狀
# 範例5-1-3-1 以下程式會畫出螺旋狀多彩的顏色 from turtle import * for steps in range(50): for c in ('blue', 'red', 'green'): color(c) forward(steps) right(30) done()
# 範例5-1-3-3 另類螺旋狀 import turtle as t t.speed(0) for i in range(0,100,3): t.forward(i) t.left(91) t.done()
5-1-3-4 Case Study個案研究 : 螺旋狀(list列表將於下個章節探討)
# 範例5-1-3-4 import turtle as t t.bgcolor("black") color = ["red","yellow","blue","white","green","purple"] t.speed(0) for i in range(0,200,2): t.pencolor(color[i%4]) t.fd(i) t.lt(35) t.done()