sp-hydra-veil-gui/gui/v2/ui/widgets/confetti.py
2026-06-13 16:19:11 -04:00

50 lines
1.4 KiB
Python
Executable file

import random
from PyQt6.QtGui import QColor
from PyQt6.QtCore import QThread, QMutex, QMutexLocker, pyqtSignal
class ConfettiParticle:
def __init__(self, x, y):
self.x = x
self.y = y
self.color = QColor(random.randint(0, 255), random.randint(
0, 255), random.randint(0, 255))
self.size = random.randint(5, 15)
self.speed = random.uniform(1, 3)
def update(self):
self.y += self.speed
class ConfettiThread(QThread):
update_signal = pyqtSignal(list)
def __init__(self, width, height):
super().__init__()
self.width = width
self.height = height
self.running = True
self.mutex = QMutex()
self.confetti = [ConfettiParticle(random.randint(
0, width), random.randint(-height, 0)) for _ in range(100)]
def run(self):
while self.running:
with QMutexLocker(self.mutex):
for particle in self.confetti:
particle.update()
if particle.y > self.height:
particle.y = random.randint(-100, 0)
particle.x = random.randint(0, self.width)
self.update_signal.emit(self.confetti.copy())
self.msleep(16)
def stop(self):
self.running = False
def update_dimensions(self, width, height):
with QMutexLocker(self.mutex):
self.width = width
self.height = height