add beat cmdline arg

This commit is contained in:
Patrick Moessler 2023-02-20 02:01:49 +01:00
parent ee1286b892
commit 9a7705fb5e

View file

@ -5,7 +5,7 @@ from typing import Generator, List, Tuple
import pygame as pg import pygame as pg
import sys import sys
from effects.effect import Effect, color_wheel, Colors from effects.effect import Effect, Colors, color_darken, color_fadeout
from effects.presets import Presets from effects.presets import Presets
@ -26,6 +26,7 @@ class Beamshow:
randomize_interval: float, randomize_interval: float,
fps: bool, fps: bool,
display: int, display: int,
beat_reactive: bool,
) -> None: ) -> None:
self.render3d = render3d self.render3d = render3d
self.windowed = window self.windowed = window
@ -36,6 +37,7 @@ class Beamshow:
self.display_id = display self.display_id = display
self.effects: List[Effect] = [] self.effects: List[Effect] = []
self.clock = pg.time.Clock() self.clock = pg.time.Clock()
self.beat_reactive = beat_reactive
pg.display.init() pg.display.init()
self.window, self.background = self.initialize() self.window, self.background = self.initialize()
@ -61,28 +63,11 @@ class Beamshow:
background = pg.Surface(win.get_size()) background = pg.Surface(win.get_size())
background.fill(Colors.Black) background.fill(Colors.Black)
self.presets = Presets(bounds=win.get_rect()) self.presets = Presets(bounds=win.get_rect(), beat_reactive=self.beat_reactive)
if self.randomize: if self.randomize:
self.effects = self.presets.randomize() self.effects = self.presets.randomize()
else: else:
from effects.moonflower import Moonflower self.effects = self.presets.default()
self.effects = [
Moonflower(
bounds=win.get_rect(),
colors=(
color_wheel(increase=75),
color_wheel(hue=180, increase=75),
),
beat_color=True,
size=win.get_height() // 4,
outer=5,
velocity=(1, 1),
rot_speed=1.5,
x_factor=(1, 1),
y_factor=(2.2, 2.2),
)
]
return win, background return win, background
@ -267,10 +252,10 @@ class Beamshow:
current_fps = self.clock.get_fps() current_fps = self.clock.get_fps()
fps_slidewindow.append(current_fps) fps_slidewindow.append(current_fps)
while len(fps_slidewindow) > 30: while len(fps_slidewindow) > 120:
fps_slidewindow.pop(0) fps_slidewindow.pop(0)
if self.print_fps: if self.print_fps:
print(f"FPS: {current_fps:3d}, avg {fps_mean:3d}") print(f"FPS: {current_fps:5.2f}, avg {fps_mean:5.2f}")
def app_main() -> None: def app_main() -> None:
@ -289,6 +274,9 @@ def app_main() -> None:
argparser.add_argument( argparser.add_argument(
"-w", "--window", action="store_true", help="Display in a window" "-w", "--window", action="store_true", help="Display in a window"
) )
argparser.add_argument(
"-b", "--beat", action="store_true", help="Effects should react to beats"
)
argparser.add_argument( argparser.add_argument(
"--trails", action="store_true", help="Fade patterns out (trail mode)" "--trails", action="store_true", help="Fade patterns out (trail mode)"
) )
@ -325,6 +313,7 @@ def app_main() -> None:
randomize_interval=args.randomize, randomize_interval=args.randomize,
fps=args.fps, fps=args.fps,
display=args.display, display=args.display,
beat_reactive=args.beat,
) )
show.main() show.main()