Learn Python by yourself: color-changing circles

Draw a circle, fill it with a different color, and change the color every three seconds.

Enter the following code:

import turtle as t

import time

ys=['green','yellow','red'] #Set the color green, yellow and red

b=t.Pen()

b.speed(10)

b.ht() #Hide the turtle cursor

for x in range(0,3):

b.color('white',ys[x%3]) #更换颜色,使用白色线,这样轮廓和背景一样,可以实现隐藏轮廓的效果

b.begin_fill() #开始填充颜色

b.circle(50) #绘制圆形

b.end_fill() #结束填充颜色

time.sleep(3) #设定3秒更换颜色

time.sleep(5)

The execution result is as follows:

image

image

image

The whole process is to change the color of the circle every 3 seconds. Think about any practical application of this? Is it similar to red and green? Finally, if your time is not very tight, and you want to improve python quickly, the most important thing is not to be afraid of hardships, I suggest that you can use WeChat: 762459510, that is really good, many people are making rapid progress and need you Don't be afraid of suffering! You can go and add it~

————————————————

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326951401&siteId=291194637