2023-02-23 02:02:57 +01:00
|
|
|
from typing import Any, Optional
|
2023-02-19 16:03:10 +01:00
|
|
|
import pygame as pg
|
2023-02-23 01:56:05 +01:00
|
|
|
from effects.effect import MovingEffect
|
2023-02-22 22:55:11 +01:00
|
|
|
from util.color import Colors, rainbow_surface
|
2023-02-23 02:02:57 +01:00
|
|
|
from util.transform import PositionGenerator
|
2023-02-19 16:03:10 +01:00
|
|
|
import math
|
|
|
|
|
|
|
|
|
2023-02-23 02:02:57 +01:00
|
|
|
class RainbowWave(MovingEffect):
|
2023-02-19 16:03:10 +01:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
bounds: pg.Rect,
|
|
|
|
wave_count: float = 2,
|
|
|
|
wave_height: int = 0,
|
|
|
|
thickness: int = 10,
|
|
|
|
hue: int = 0,
|
|
|
|
color_inc: int = 1,
|
|
|
|
start_phase: int = 0,
|
|
|
|
scroll_speed: float = 5,
|
2023-02-23 01:56:05 +01:00
|
|
|
mover: Optional[PositionGenerator] = None,
|
2023-02-19 16:03:10 +01:00
|
|
|
*groups: pg.sprite.Group
|
|
|
|
) -> None:
|
|
|
|
image = pg.Surface(bounds.size)
|
|
|
|
image.fill(Colors.Black)
|
|
|
|
image.set_colorkey(Colors.Black)
|
2023-02-23 01:56:05 +01:00
|
|
|
super().__init__(image, bounds, mover, *groups)
|
2023-02-19 16:03:10 +01:00
|
|
|
self.subrect = pg.rect.Rect(0, 0, bounds.width, bounds.height)
|
2023-02-23 01:56:05 +01:00
|
|
|
|
|
|
|
self.wave_height = wave_height or bounds.height
|
2023-02-19 16:03:10 +01:00
|
|
|
self.bounds = bounds
|
|
|
|
self.scroll_speed = scroll_speed
|
|
|
|
|
|
|
|
self.rainbow = pg.Surface((bounds.width, self.wave_height))
|
|
|
|
rainbow_surface(self.rainbow, "h", hue, color_inc)
|
|
|
|
|
|
|
|
self.wave_image = pg.Surface(
|
|
|
|
(bounds.width * (wave_count + 1) / wave_count, self.wave_height)
|
|
|
|
)
|
|
|
|
self.wave_image.fill(Colors.Black)
|
|
|
|
self.wave_image.set_colorkey(Colors.Black)
|
|
|
|
|
|
|
|
y_halfheight = self.wave_image.get_height() // 2
|
|
|
|
points = [
|
|
|
|
(
|
|
|
|
x,
|
|
|
|
y_halfheight
|
|
|
|
+ (y_halfheight - thickness)
|
|
|
|
* math.sin(
|
|
|
|
math.pi
|
|
|
|
* (
|
|
|
|
start_phase / 180
|
|
|
|
+ x / self.wave_image.get_width() * 2 * (wave_count + 1)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
for x in range(self.wave_image.get_width())
|
|
|
|
]
|
|
|
|
|
|
|
|
pg.draw.lines(self.wave_image, Colors.White, False, points, width=thickness)
|
|
|
|
|
|
|
|
pg.draw.lines(
|
|
|
|
self.wave_image,
|
|
|
|
Colors.White,
|
|
|
|
False,
|
|
|
|
[(x + 2, y) for x, y in points],
|
|
|
|
width=thickness,
|
|
|
|
)
|
|
|
|
|
2023-02-22 22:55:11 +01:00
|
|
|
self.update(is_beat=False)
|
2023-02-19 16:03:10 +01:00
|
|
|
|
|
|
|
def update(self, *args: Any, **kwargs: Any) -> None:
|
|
|
|
|
|
|
|
self.image.fill(Colors.Black)
|
|
|
|
|
|
|
|
# rainbow_surface(self.image)
|
|
|
|
|
2023-02-23 01:56:05 +01:00
|
|
|
pos = self.mover.send(
|
|
|
|
((self.bounds.width, self.wave_height), kwargs["is_beat"])
|
|
|
|
)
|
|
|
|
# pg.draw.rect(self.image, Colors.Black, (0, 0, self.bounds.width, pos[1]))
|
|
|
|
# pg.draw.rect(
|
|
|
|
# self.image,
|
|
|
|
# Colors.Black,
|
|
|
|
# (
|
|
|
|
# 0,
|
|
|
|
# pos[1] + self.wave_height,
|
|
|
|
# self.bounds.width,
|
|
|
|
# self.bounds.height - pos[1] + self.wave_height,
|
|
|
|
# ),
|
|
|
|
# )
|
2023-02-19 16:03:10 +01:00
|
|
|
|
|
|
|
self.image.blit(self.rainbow, pos)
|
|
|
|
self.image.blit(self.wave_image, pos, self.subrect, pg.BLEND_MULT)
|
|
|
|
|
|
|
|
self.subrect.move_ip(self.scroll_speed, 0)
|
|
|
|
if self.subrect.right >= self.wave_image.get_rect().right:
|
|
|
|
self.subrect.left = 0
|
|
|
|
|
|
|
|
# pg.draw.ellipse(
|
|
|
|
# self.image,
|
2023-02-24 18:21:21 +01:00
|
|
|
# next(self.color),
|
2023-02-19 16:03:10 +01:00
|
|
|
# ((0, 0), self.rect.size),
|
|
|
|
# )
|
|
|
|
|
|
|
|
# self.ticks += int(self.velocity / 180 * math.pi)
|
|
|
|
# self.velocity = random.randint(self.min_velocity, self.max_velocity)
|