pybeamshow/effects/presets.py
2023-02-22 22:55:11 +01:00

205 lines
6.1 KiB
Python

import pygame as pg
from typing import List
from random import choice, randint
from effects.effect import Effect
from util.color import color_darken, color_randomize, color_wheel, Colors
from effects.crazypolys import CrazyPolys
from effects.drops import Drops
from effects.bouncingspot import BouncingSpot
from effects.doublespot import DoubleSpot
from effects.moonflower import Moonflower
from effects.movingwave import MovingWave
from effects.rotatingpoly import RotatingPoly
from effects.scanreticle import ScanReticle
from effects.spiro import Spiro
from effects.starfield import Starfield
class Presets:
def __init__(self, bounds: pg.Rect, beat_reactive: bool = False) -> None:
self.bounds = bounds
self.beat_reactive = beat_reactive
def default(self) -> List[Effect]:
return self.Moonflower()
def randomize(self) -> List[Effect]:
return getattr(
self,
choice(
[
func
for func in dir(self)
if callable(getattr(self, func)) and not func.startswith("__")
]
),
)()
def DoubleSpotRandomColor(self) -> List[Effect]:
return [
DoubleSpot(
bounds=self.bounds,
color=color_wheel(increase=30),
beat_adapt=self.beat_reactive,
radius=100,
fade_out=True,
fade_in=True,
hold=60,
)
]
def DoubleBouncingSpotsColorWheel(self) -> List[Effect]:
return [
BouncingSpot(
bounds=self.bounds,
color=color_wheel(),
sizes=(self.bounds.height / 12, self.bounds.height / 10),
),
BouncingSpot(
bounds=self.bounds,
color=color_wheel(hue=180),
sizes=(self.bounds.height / 12, self.bounds.height / 10),
),
]
def CollidingWaves(self) -> List[Effect]:
return [
MovingWave(
bounds=pg.rect.Rect(0, 0, self.bounds.width, self.bounds.height),
wave_count=5,
wave_height=self.bounds.height // 6,
thickness=20,
),
MovingWave(
bounds=pg.rect.Rect(0, 0, self.bounds.width, self.bounds.height),
hue=180,
wave_count=5,
wave_height=self.bounds.height // 6,
start_phase=120,
start_pos=(0, self.bounds.height * 5 // 6),
thickness=20,
),
]
def BouncingSpotWhite(self) -> List[Effect]:
return [
BouncingSpot(
bounds=self.bounds,
color=Colors.White,
# color=color_wheel(),
sizes=(self.bounds.height / 8, self.bounds.height / 8),
velocity=(1, 1),
x_factor=(1, 1),
y_factor=(2.2, 2.2),
),
]
def RotatingPoly(self) -> List[Effect]:
return [
RotatingPoly(
bounds=self.bounds,
color=color_wheel(increase=(75 if self.beat_reactive else 0)),
beat_color=self.beat_reactive,
size=int(self.bounds.height * 0.8),
outer=randint(3, 8),
velocity=(0.5, 0.5),
rot_speed=1,
x_factor=(0.5, 1.5),
y_factor=(0.5, 3),
)
]
def Moonflower(self) -> List[Effect]:
return [
Moonflower(
bounds=self.bounds,
colors=(
color_wheel(increase=(75 if self.beat_reactive else 0)),
color_wheel(hue=180, increase=(75 if self.beat_reactive else 0)),
),
beat_color=self.beat_reactive,
size=self.bounds.height // 4,
outer=5,
velocity=(1, 1),
rot_speed=1.5,
x_factor=(1, 1),
y_factor=(2.2, 2.2),
)
]
def WhiteStarfield(self) -> List[Effect]:
return [
Starfield(
bounds=self.bounds,
color=Colors.White,
# color=color_randomize(),
fade_in=True,
fade_out=True,
# radius=30,
star_factor=1,
hold=60 * 2,
# beat_adapt=True,
)
]
def ColorStarfield(self) -> List[Effect]:
return [
Starfield(
bounds=self.bounds,
color=color_randomize(),
fade_in=True,
fade_out=True,
# radius=30,
star_factor=1,
hold=60 * 2,
beat_adapt=True,
)
]
def GreenBlueDrops(self) -> List[Effect]:
return [
Drops(
bounds=self.bounds,
colors=(Colors.Green, color_darken(Colors.Blue, 0.2)),
sizes=(self.bounds.width // 40, self.bounds.width // 35),
drop_rate=0.1,
drop_acceleration=0.3,
)
]
def ScanReticle(self) -> List[Effect]:
return [
ScanReticle(
self.bounds,
(Colors.Red, Colors.White),
velocity=(1, 1),
x_factor=(0.4, 1),
y_factor=(0.2, 1),
)
]
def Spiro(self) -> List[Effect]:
return [
Spiro(
bounds=self.bounds,
color=color_wheel(increase=2),
sizes=(self.bounds.height, self.bounds.height),
velocity=(0.1, 0.4),
y_factor=(0.5, 1.5),
),
]
def CrazyPolys(self) -> List[Effect]:
return [
CrazyPolys(
bounds=self.bounds,
color=color_wheel(increase=2),
sizes=(self.bounds.height, self.bounds.height),
velocity=(0.1, 0.4),
y_factor=(0.5, 1.5),
),
]