猫史档案馆


【Python作品分享】七彩泡泡【作品秀】

用户:快乐雷电猴快乐雷电猴查看:0 回复:0 评论:0 创建时间:2021-09-19T12:23:13


【作品展示】

center_image

 

【作品介绍】

-------

 

【作品源代码】

#导入库
import turtle
import random
import time

#创建屏幕
m = turtle.Screen()
m.title('七彩泡泡')
m.bgpic('bg.gif')
m.setup(960, 600)
m.tracer(0)

#画笔创建
p = turtle.Pen()
p.hideturtle()
p.penup()

#创建泡泡类
class Bubble:
    x = None
    y = None
    size = None
    color = None
    speedx = None
    speedy = None

#泡泡列表
bubble_list = []

def create_bubble(x,y):
    b = Bubble()
    b.x = x
    b.y = y
    b.size = random.randint(10,50)
    colors = ['red','yellow','blue','cyan']
    b.color = random.choice(colors)
    b.speedx = random.randint(-5,5)
    b.speedy = random.randint(-5,5)
    bubble_list.append(b)

#画泡泡
def draw_bubble(x,y,size,color):
    p.goto(x,y)
    p.dot(size,color)
    p.dot(size*0.9,'white')

m.onclick(create_bubble,1)

def move():
    for b in bubble_list:
        #泡泡绘制
        draw_bubble(b.x,b.y,b.size,b.color)
        #移动
        b.x += b.speedx
        b.y += b.speedy

while True:
    move()
    m.update()
    time.sleep(0.01)
    p.clear()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页