本篇文章给大家谈谈python绘制烟花特定爆炸效果,以及python炫酷烟花表白源代码,希望对各位有所帮助,不要忘了收藏本站喔。
import pygame
from random import randint, uniform, choice
import math
vector = pygame.math.Vector2
gravity = vector(0, 0.3)
DISPLAY_WIDTH = DISPLAY_HEIGHT = 800
trail_colours = [(45, 45, 45), (60, 60, 60), (75, 75, 75),
(125, 125, 125), (150, 150, 150)]
dynamic_offset = 1
static_offset = 5
class Firework:
def __init__(self):
self.colour = (randint(0, 255), randint(0, 255), randint(0, 255))
self.colours = (
(randint(0, 255), randint(0, 255), randint(0, 255)
), (randint(0, 255), randint(0, 255), randint(0, 255)),
(randint(0, 255), randint(0, 255), randint(0, 255)))
self.firework = Particle(randint(0, DISPLAY_WIDTH), DISPLAY_HEIGHT, True,
self.colour) # Creates the firework particle
self.exploded = False
self.particles = []
self.min_max_particles = vector(100, 225)
def update(self, win): # called every frame
if not self.exploded:
self.firework.apply_force(gravity)
self.firework.move()
for tf in self.firework.trails:
tf.show(win)
self.show(win)
if self.firework.vel.y >= 0:
se