亲爱的朋友们:
写点什么呢,我已经停更两个月了。2023年快结束了,时间真的过得好快,总要写点什么留下纪念吧。这一年伴随着许多挑战和机会,给了我无数的成长和体验。坦白说,有时候我觉得自己好像是在时间的漩涡中被席卷着,努力地追逐着每一个梦想,却又无法把握住每一刻的风景。
这两个月的停更让我重新审视了自己的生活和选择。我意识到,我需要给自己留出一些时间来回首过去,反思成长,并重新调整自己的目标与方向。停下脚步,也不意味着停止前进,而是为了更好地迎接未来的挑战。
在这段停更的时间里,我为自己提出了一些问题:我真正追求的是什么?我为什么会开始这个旅程?曾经的热情和动力是否还在?而答案,从内心深处浮现:记录知识,不让自己忘记来时的路,生活总要有迹可循吧。
回顾这一年,我经历了许多学习和探索的时刻。尽管有时候面临着困难和挫折,但是每一次克服困难的过程都让我更加坚定了自己的决心。在每一个成功的背后,都蕴藏着无数的努力和坚持。
正因为有了你们的陪伴和支持,我才能够坚定地走到今天。你们的鼓励和反馈是我前进的动力,是我坚持不断学习和成长的源泉。感谢你们,你们的真情实感是我前行路上最美丽的风景。
我知道,未来的道路依然会有风雨和坎坷,但这不会阻止我努力前行。我将继续努力,保持初心,并且永远保持对知识的渴望和求索。
2023年的最后时刻,我希望你们也能找到属于自己的答案,找到自己激情的源泉。无论是过去的成就还是未来的挑战,都是值得被铭记的一部分,让我们珍惜每一次成长的机会。
谢谢你们一直以来的陪伴,愿我们在新的一年里继续同行,共同为更美好的未来努力!
最诚挚的祝福
Dr.sky
新年福利:基于python的电子烟花实现
import pygame as pg
import random as ra
import math
pg.init()
pg.display.set_caption("🎇")
winScreen = pg.display.Info()
screenWidth = winScreen.current_w
screenHeight = winScreen.current_h
vector = pg.math.Vector2
trail_colors = [(45, 45, 45), (60, 60, 60), (75, 75, 75), (125, 125, 125), (150, 150, 150)]
# 烟花类
class Firework:def __init__(self):# 随机生成颜色self.colour = (ra.randint(0, 255), ra.randint(0, 255), ra.randint(0, 255))# 随机生成三种颜色self.colours = ((ra.randint(0, 255), ra.randint(0, 255), ra.randint(0, 255)),(ra.randint(0, 255), ra.randint(0, 255), ra.randint(0, 255)),(ra.randint(0, 255), ra.randint(0, 255), ra.randint(0, 255)))# 生成一个表示发射出的火花的粒子对象self.firework = Particle(ra.randint(0,screenWidth), screenHeight, True, self.colour)# 初始化爆炸状态为 Falseself.exploded = Falseself.particles = []# 爆炸产生的粒子数量范围self.min_max_particles = vector(666, 999)def update(self, win):g = vector(0, ra.uniform(0.15, 0.4))if not self.exploded:# 给发射出的火花施加重力self.firework.apply_force(g)self.firework.move()for tf in self.firework.trails:tf.show(win)self.show(win)if self.firework.vel.y >= 0:self.exploded = Trueself.explode()else:for particle in self.particles:# 给爆炸产生的粒子施加随机力particle.apply_force(vector(g.x + ra.uniform(-1, 1) / 20, g.y / 2 + (ra.randint(1, 8) / 100)))particle.move()for t in particle.trails:t.show(win)particle.show(win)def explode(self):amount = ra.randint(int(self.min_max_particles.x), int(self.min_max_particles.y))for i in range(amount):# 在爆炸位置生成粒子对象并添加到粒子列表中self.particles.append(Particle(self.firework.pos.x, self.firework.pos.y, False, self.colours))def show(self, win):# 绘制发射出的火花pg.draw.circle(win, self.colour, (int(self.firework.pos.x), int(self.firework.pos.y)), self.firework.size)def remove(self):if self.exploded:for p in self.particles:if p.remove is True:self.particles.remove(p)if len(self.particles) == 0:return Trueelse:return False
# 粒子类
class Particle:def __init__(self, x, y, firework, colour):self.firework = fireworkself.pos = vector(x, y)self.origin = vector(x, y)self.radius = 25self.remove = Falseself.explosion_radius = ra.randint(15, 25)self.life = 0self.acc = vector(0, 0)self.trails = []self.prev_posx = [-10] * 10self.prev_posy = [-10] * 10if self.firework:self.vel = vector(0, -ra.randint(17, 20))self.size = 5self.colour = colourfor i in range(5):self.trails.append(Trail(i, self.size, True))else:self.vel = vector(ra.uniform(-1, 1), ra.uniform(-1, 1))self.vel.x *= ra.randint(7, self.explosion_radius + 2)self.vel.y *= ra.randint(7, self.explosion_radius + 2)self.size = ra.randint(2, 4)self.colour = ra.choice(colour)for i in range(5):self.trails.append(Trail(i, self.size, False))def apply_force(self, force):# 施加力self.acc += forcedef move(self):if not self.firework:# 爆炸产生的粒子减速self.vel.x *= 0.8self.vel.y *= 0.8self.vel += self.accself.pos += self.velself.acc *= 0if self.life == 0 and not self.firework:# 判断是否超出爆炸半径distance = math.sqrt((self.pos.x - self.origin.x) ** 2 + (self.pos.y - self.origin.y) ** 2)if distance > self.explosion_radius:self.remove = Trueself.decay()self.trail_update()self.life += 1def show(self, win):# 绘制粒子pg.draw.circle(win, (self.colour[0], self.colour[1], self.colour[2], 0), (int(self.pos.x), int(self.pos.y)), self.size)def decay(self):if 50 > self.life > 10:ran = ra.randint(0, 30)if ran == 0:self.remove = Trueelif self.life > 50:ran = ra.randint(0, 5)if ran == 0:self.remove = Truedef trail_update(self):self.prev_posx.pop()self.prev_posx.insert(0, int(self.pos.x))self.prev_posy.pop()self.prev_posy.insert(0, int(self.pos.y))for n, t in enumerate(self.trails):if t.dynamic:t.get_pos(self.prev_posx[n + 1], self.prev_posy[n + 1])else:t.get_pos(self.prev_posx[n + 5], self.prev_posy[n + 5])
# 痕迹类
class Trail:def __init__(self, n, size, dynamic):self.pos_in_line = nself.pos = vector(-10, -10)self.dynamic = dynamicif self.dynamic:self.colour = trail_colors[n]self.size = int(size - n / 2)else:self.colour = (255, 255, 200)self.size = size - 2if self.size < 0:self.size = 0def get_pos(self, x, y):self.pos = vector(x, y)def show(self, win):# 绘制痕迹pg.draw.circle(win, self.colour, (int(self.pos.x), int(self.pos.y)), self.size)
def update(win, fireworks):for fw in fireworks:fw.update(win)if fw.remove():fireworks.remove(fw)pg.display.update()
def fire():screen = pg.display.set_mode((screenWidth, screenHeight - 66))clock = pg.time.Clock()fireworks = [Firework() for i in range(2)]running = True# 加载字体font = pg.font.SysFont("comicsansms", 99)# 渲染文本text = "Happy New Year!"text_color = (255, 190, 200) # 字体颜色rendered_text = font.render(text, True, text_color)while running:clock.tick(99)for event in pg.event.get():if event.type == pg.QUIT:running = False# 计算文本位置text_width = rendered_text.get_width()text_height = rendered_text.get_height()text_x = (screenWidth - text_width) // 2text_y = (screenHeight - text_height) // 2 - 99screen.fill((20, 20, 30))# 绘制文本screen.blit(rendered_text, (text_x, text_y))if ra.randint(0, 10) == 1:fireworks.append(Firework())update(screen, fireworks)pg.quit()quit()
if __name__ == "__main__":fire()
友情提示:记得安装pygame库
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pygame
烟花效果: