1,渐变色圆
import pgzrun
def draw():
screen.fill('white')
for r in range(255,0,-1):
screen.draw.filled_circle((400,300),r,(255-r,0,0))
pgzrun.go()
2,很多个同心圆,使用了 #--------for循环嵌套--------------
range()是一个函数,可以用来生成一个自然数的序列
r = range(5) # 生成一个这样的序列[0,1,2,3,4]:
import pgzrun
def draw():
screen.fill('white')
for r in range(1,201,10):#(r)半径 1<=r<201,每次加10
screen.draw.circle((400,300),r,"black")
pgzrun.go()
3,鼠标点按def on_mouse_down(): 出现随机颜色的同心圆:
import pgzrun
import random
def draw():
screen.fill('white')
#n = random.randint(0,255) ( 下面不能代入n,不然rgb三个色数值一样。)
for r in range(255,0,-10):
#例:screen.draw.filled_circle((400,300),r,(255-r,0,0)) #三个 ,(85是间隔距离,如果85改成1,渐变更自然)颜色渐变圆
screen.draw.filled_circle((400, 300), r, \
(random.randint(0,255), random.randint(0,255) , \
random. randint(0,255)))#三个颜色随机的同心圆,r是将颜色分为三种(可以在r,g,b任何位置)
def on_mouse_down(): #鼠标按下画的圆都会发生变化,不必重新弹窗
draw()
pgzrun.go()