pybeamshow/effects/chase_circle.py
2023-02-24 23:33:37 +01:00

72 lines
2.1 KiB
Python

from effects.effect import MovingEffect
from typing import Any, Optional, Tuple
from util.color import Colors, ColorGenerator
import math
import pygame as pg
from util.transform import PositionGenerator
class ChaseCircle(MovingEffect):
def __init__(
self,
bounds: pg.Rect,
colors: Tuple[ColorGenerator, ColorGenerator],
size: int = 200,
rot_speed: float = 0.5,
thickness: int = 30,
size_factor: float = 1.0,
mover: Optional[PositionGenerator] = None,
on_beat_color: bool = False,
*groups: pg.sprite.Group
) -> None:
self.color_gen = colors
self.colors = (next(self.color_gen[0]), next(self.color_gen[1]))
self.on_beat_color = on_beat_color
self.angle = 0.0
self.rot_speed = rot_speed / 180 * math.pi
self.thickness = thickness
self.size_f = size_factor
image = pg.Surface((size, size))
image.fill(Colors.Black)
image.set_colorkey(Colors.Black)
super().__init__(
image,
pg.Rect(
bounds.centerx - size / 2,
bounds.centery - size / 2,
size,
size,
),
mover,
*groups
)
self.update(is_beat=True)
def update(self, *args: Any, **kwargs: Any) -> None:
self.rect.center = self.mover.send((self.rect.size, kwargs["is_beat"]))
if (not self.on_beat_color) or kwargs["is_beat"]:
self.colors = (next(self.color_gen[0]), next(self.color_gen[1]))
self.image.fill(Colors.Black)
pg.draw.arc(
self.image,
self.colors[0],
self.image.get_rect(),
self.angle,
self.angle + math.pi * self.size_f,
self.thickness,
)
pg.draw.arc(
self.image,
self.colors[1],
self.image.get_rect(),
self.angle + math.pi * self.size_f,
self.angle,
self.thickness,
)
self.angle = (self.angle + self.rot_speed) % (2 * math.pi)