Rate My Life

import pygame import random import math class Particle: def __init__(self, x, y): self.x = x self.y = y self.size = random.randint(2, 5) self.color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) self.velocity_x = random.uniform(-3, 3) self.velocity_y = random.uniform(-7, -3) self.gravity = 0.1 self.life_span = 50 def update(self): self.velocity_y += self.gravity self.x += self.velocity_x self.y += self.velocity_y self.life_span -= 1 def draw(self, screen): if self.life_span > 0: alpha = int((self.life_span / 50) * 255) surface = pygame.Surface((self.size*2, self.size*2), pygame.SRCALPHA) pygame.draw.circle(surface, color_with_alpha, (self.size, self.size), self.size) screen.blit(surface, (int(self.x-self.size), int(self.y-self.size))) def create_firework(x, y): particles = [] for _ in range(random.randint(80, 120)): particles.append(Particle(x, y)) return particles pygame.init() screen_width, screen_height = 800, 600 screen = pygame.display.set_mode((screen_width, screen_height)) clock = pygame.time.Clock() fireworks = [] running = True while running: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: mx, my = pygame.mouse.get_pos() fireworks.extend(create_firework(mx, my)) for firework in fireworks[:]: firework.update() firework.draw(screen) if firework.life_span <= 0: fireworks.remove(firework) pygame.display.flip() clock.tick(60) pygame.quit()将这段代码修改让其可以在processing中运行
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值