rainbow
1. List (color box)
1.1 Overview
1.2 How to use the color box
from turtle import*
ylh=('blue','green','red')
for c in range(3):
pencolor(ylh[c%3])
fd(200)
right(120)
2. Coordinate movement
In real life:
Where will the rainbow appear?
Programming: I can set the position of the rainbow~
The coordinates will be used here:
2.1 setx( )
Move the current x-axis to the specified position, leaving the y-axis unchanged (fill in the coordinate numbers in the brackets)
2.2 sets( )
Move the current y-axis to the specified position, leaving the x-axis unchanged (fill in the coordinate numbers in the brackets)
3. Draw a rainbow
3.1 Rainbow shape
3.2 Rainbow lines
Look carefully: Does the rainbow have many lines?
We just drew a rainbow line. What knowledge points do we need to use to create multiple rainbows?
The answer is: 循环
The coordinates are setx(300-c*20)
The initial position of the outermost rainbow x is 300 , does every rainbow inside need to be moved inside? Suppose the line size is set to 20, then we need to subtract 20 from each line, so that the rainbow lines will not touch each other~
from turtle import *
lt(90)
pensize(20)
for c in range(7):
pu()
setx(300-c*20),
pd()
circle(300-c*20,180)
lt(180)
But at this time the rainbow is black and needs to be colored next.
4. Complete code
from turtle import *
speed(0)
#a=('red','orange','yellow','green','cyan','blue','violet','white')#设置颜料盒
a=('red','orange','yellow','green','cyan','blue','purple','violet')
lt(90)
pensize(20)
for c in range(7):
pu()
setx(300-c*20)
pd()
pencolor(a[c%8]) #根据颜料盒中的记数牌改颜色
circle(300-c*20,180)
lt(180)
done()
5. Color Runway
from turtle import * #导入海龟库
speed(0) #设置画笔速度
pensize(10) #彩虹的宽度
a=('red','orange','yellow','green','cyan','blue','violet','white') #制作颜料盒
for c in range(7): #循环
pu() #抬笔
sety(-200+c*20) #设置y坐标
pd() #落笔
pencolor(a[c%8]) #笔的颜色
circle(200-c*20,180) #画半圆
fd(200) #画直线
circle(200-c*20,180) #画半圆
fd(200) #画直线
pu()
goto(0,0)
for i in range(7):
pencolor(a[i%8])
dot(10*(7-i))
pu()
goto(-160,0)
for i in range(7):
pencolor(a[i%8])
dot(10*(7-i))
done()