一、基本画法,顺序结构
from turtle import *
speed(0)
pensize(10)
pencolor('red')
left(90)
circle(40,180)
right(90)
forward(10)
right(90)
pencolor('orange')
circle(-50,180)
left(90)
forward(10)
left(90)
pencolor('yellow')
circle(60,180)
right(90)
forward(10)
right(90)
pencolor('green')
circle(-70,180)
left(90)
forward(10)
left(90)
pencolor('cyan')
circle(80,180)
right(90)
forward(10)
right(90)
pencolor('blue')
circle(-90,180)
left(90)
forward(10)
left(90)
pencolor('purple')
circle(100,180)
二、循环结构、列表使用
from turtle import *
#rainbow_color列表存彩虹颜色
rainbow_color=["red","orange","yellow","green","cyan","blue","purple"]
pensize(12) #设置彩虹的宽度,即画笔的粗细
for i in range(7):
fd(i*10) #画笔起笔位置
left(90) #切线方向
pendown() #落笔
pencolor(rainbow_color[i]) #取彩虹的颜色,即画笔颜色
circle(i*10+100,180) #画弧
penup() #起笔
home() #回到原点
ht() #隐藏画笔
颜色可以自由选择。