From 9a7705fb5e838fa199ea2d808e04d4d777ad0c00 Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Mon, 20 Feb 2023 02:01:49 +0100 Subject: [PATCH] add beat cmdline arg --- beamshow.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/beamshow.py b/beamshow.py index 538d31c..d919c5a 100644 --- a/beamshow.py +++ b/beamshow.py @@ -5,7 +5,7 @@ from typing import Generator, List, Tuple import pygame as pg 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 @@ -26,6 +26,7 @@ class Beamshow: randomize_interval: float, fps: bool, display: int, + beat_reactive: bool, ) -> None: self.render3d = render3d self.windowed = window @@ -36,6 +37,7 @@ class Beamshow: self.display_id = display self.effects: List[Effect] = [] self.clock = pg.time.Clock() + self.beat_reactive = beat_reactive pg.display.init() self.window, self.background = self.initialize() @@ -61,28 +63,11 @@ class Beamshow: background = pg.Surface(win.get_size()) 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: self.effects = self.presets.randomize() else: - from effects.moonflower import Moonflower - - 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), - ) - ] + self.effects = self.presets.default() return win, background @@ -267,10 +252,10 @@ class Beamshow: current_fps = self.clock.get_fps() fps_slidewindow.append(current_fps) - while len(fps_slidewindow) > 30: + while len(fps_slidewindow) > 120: fps_slidewindow.pop(0) 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: @@ -289,6 +274,9 @@ def app_main() -> None: argparser.add_argument( "-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( "--trails", action="store_true", help="Fade patterns out (trail mode)" ) @@ -325,6 +313,7 @@ def app_main() -> None: randomize_interval=args.randomize, fps=args.fps, display=args.display, + beat_reactive=args.beat, ) show.main()