50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import pygame
|
|
from pygame import transform, gfxdraw, Vector2
|
|
from math import sin, cos, pi
|
|
|
|
from time import time, sleep
|
|
from random import random
|
|
|
|
class Star:
|
|
def __init__(self, _id: int, x: int, y: int, alpha: float, rot: float, scale: float, offset: float, image: pygame.Surface):
|
|
self.id = _id
|
|
self.x = x
|
|
self.y = y
|
|
self.rot = rot
|
|
self.alpha = alpha
|
|
self.scale = scale
|
|
self.offset = offset
|
|
self.image = image
|
|
|
|
class Screen:
|
|
def __init__(self, stars: list[Star]) -> None:
|
|
if not pygame.get_init():
|
|
pygame.init()
|
|
self.screen = pygame.display.set_mode((1920, 1080))
|
|
self.clock = pygame.time.Clock()
|
|
self.stars = stars
|
|
self.last = time()
|
|
self.brightness = 1.0
|
|
|
|
|
|
def update(self):
|
|
self.screen.fill((0, 0, 0))
|
|
now = time()
|
|
delta = now - self.last
|
|
self.last = now
|
|
for star in self.stars:
|
|
star.alpha += star.rot * delta
|
|
scaled = transform.rotozoom(star.image, star.alpha, star.scale)
|
|
(w, h) = scaled.get_size()
|
|
pos = (star.x*self.screen.get_width() - w/2, star.y*self.screen.get_height() - h/2)
|
|
self.screen.blit(scaled, pos)
|
|
|
|
overlay = pygame.surface.Surface((1920, 1080), depth=32)
|
|
overlay.set_alpha(int(255 * (1 - self.brightness)))
|
|
self.screen.blit(overlay, (0, 0))
|
|
|
|
pygame.display.flip()
|
|
self.clock.tick(60)
|
|
|
|
def close(self):
|
|
pygame.quit() |