Add presets
This commit is contained in:
parent
5a28453d2e
commit
3b8449f00c
2 changed files with 100 additions and 22 deletions
41
beamshow.py
41
beamshow.py
|
@ -1,5 +1,5 @@
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from typing import Iterable, Tuple
|
from typing import Iterable, List, Tuple
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
import math
|
import math
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
@ -8,7 +8,9 @@ import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from effects.bouncingspot import BouncingSpot
|
from effects.bouncingspot import BouncingSpot
|
||||||
from effects.effect import Effect, color_wheel
|
from effects.doublespot import DoubleSpot
|
||||||
|
from effects.effect import Effect, color_randomize, color_wheel, Colors
|
||||||
|
from effects.presets import Presets
|
||||||
|
|
||||||
|
|
||||||
def print_displays() -> None:
|
def print_displays() -> None:
|
||||||
|
@ -41,7 +43,7 @@ def initialize(
|
||||||
background.fill(pg.Color(0, 0, 0, 5))
|
background.fill(pg.Color(0, 0, 0, 5))
|
||||||
else:
|
else:
|
||||||
background = pg.Surface(win.get_size())
|
background = pg.Surface(win.get_size())
|
||||||
background.fill(pg.Color(0, 0, 0))
|
background.fill(Colors.Black)
|
||||||
return win, background
|
return win, background
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +78,7 @@ def render_loop_3d(
|
||||||
clock: pg.time.Clock,
|
clock: pg.time.Clock,
|
||||||
) -> None:
|
) -> None:
|
||||||
stage = pg.Surface(size=window.get_size())
|
stage = pg.Surface(size=window.get_size())
|
||||||
stage.fill(Color(0, 0, 0))
|
stage.fill(Colors.Black)
|
||||||
|
|
||||||
full_size = stage.get_size()
|
full_size = stage.get_size()
|
||||||
scaled_sizes = [
|
scaled_sizes = [
|
||||||
|
@ -98,10 +100,10 @@ def render_loop_3d(
|
||||||
e.update()
|
e.update()
|
||||||
e.draw(stage)
|
e.draw(stage)
|
||||||
|
|
||||||
window.fill(Color(0, 0, 0))
|
window.fill(Colors.Black)
|
||||||
|
|
||||||
stage.set_colorkey(Color(0, 0, 0))
|
stage.set_colorkey(Colors.Black)
|
||||||
for i in range(0, 101, 5):
|
for i in range(0, 101, 4):
|
||||||
stage.set_alpha(192 - 192 * ((i / 100) ** 0.5))
|
stage.set_alpha(192 - 192 * ((i / 100) ** 0.5))
|
||||||
window.blit(
|
window.blit(
|
||||||
pg.transform.scale(stage, scaled_sizes[int(100 * (i / 100) ** 2)]),
|
pg.transform.scale(stage, scaled_sizes[int(100 * (i / 100) ** 2)]),
|
||||||
|
@ -129,6 +131,15 @@ def main() -> None:
|
||||||
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)"
|
||||||
)
|
)
|
||||||
|
argparser.add_argument(
|
||||||
|
"--randomize",
|
||||||
|
metavar="N",
|
||||||
|
type=int,
|
||||||
|
nargs="?",
|
||||||
|
default=0,
|
||||||
|
const=5,
|
||||||
|
help="Select random effect presets after <N> seconds",
|
||||||
|
)
|
||||||
argparser.add_argument("--fps", action="store_true", help="Show FPS in console")
|
argparser.add_argument("--fps", action="store_true", help="Show FPS in console")
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"-d", "--display", type=int, default=0, help="ID of the display to use"
|
"-d", "--display", type=int, default=0, help="ID of the display to use"
|
||||||
|
@ -150,18 +161,20 @@ def main() -> None:
|
||||||
display_id=args.display, windowed=args.window, trails=args.trails
|
display_id=args.display, windowed=args.window, trails=args.trails
|
||||||
)
|
)
|
||||||
|
|
||||||
|
presets = Presets(bounds=window.get_rect())
|
||||||
|
if args.randomize:
|
||||||
|
effects = presets.randomize()
|
||||||
|
else:
|
||||||
effects = [
|
effects = [
|
||||||
BouncingSpot(
|
BouncingSpot(
|
||||||
bounds=window.get_rect(),
|
bounds=window.get_rect(),
|
||||||
color=pg.Color(255, 255, 255),
|
color=Colors.White,
|
||||||
# color=color_wheel(),
|
# color=color_wheel(),
|
||||||
sizes=(window.get_height() / 8, window.get_height() / 8),
|
sizes=(window.get_height() / 8, window.get_height() / 8),
|
||||||
velocity=(1, 1),
|
velocity=(1, 1),
|
||||||
x_factor=(1, 1),
|
x_factor=(1, 1),
|
||||||
y_factor=(2.2, 2.2),
|
y_factor=(2.2, 2.2),
|
||||||
),
|
),
|
||||||
BouncingSpot(bounds=window.get_rect(), color=color_wheel()),
|
|
||||||
BouncingSpot(bounds=window.get_rect(), color=color_wheel(hue=180)),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
clock = pg.time.Clock()
|
clock = pg.time.Clock()
|
||||||
|
@ -171,10 +184,18 @@ def main() -> None:
|
||||||
else:
|
else:
|
||||||
loop = render_loop_normal(window, background, effects, clock)
|
loop = render_loop_normal(window, background, effects, clock)
|
||||||
|
|
||||||
|
framecounter = 0
|
||||||
while True:
|
while True:
|
||||||
next(loop)
|
next(loop)
|
||||||
pg.display.flip()
|
pg.display.flip()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
framecounter += 1
|
||||||
|
|
||||||
|
if args.randomize:
|
||||||
|
if (framecounter % (args.randomize * 60)) == 0:
|
||||||
|
effects.clear()
|
||||||
|
effects.extend(presets.randomize())
|
||||||
|
|
||||||
if args.fps:
|
if args.fps:
|
||||||
print(clock.get_fps())
|
print(clock.get_fps())
|
||||||
|
|
||||||
|
|
57
effects/presets.py
Normal file
57
effects/presets.py
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
from random import choice
|
||||||
|
from typing import List
|
||||||
|
from effects.effect import Effect, color_randomize, color_wheel, Colors
|
||||||
|
from effects.bouncingspot import BouncingSpot
|
||||||
|
from effects.doublespot import DoubleSpot
|
||||||
|
import pygame as pg
|
||||||
|
|
||||||
|
|
||||||
|
class Presets:
|
||||||
|
def __init__(self, bounds: pg.Rect) -> None:
|
||||||
|
self.bounds = bounds
|
||||||
|
|
||||||
|
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),
|
||||||
|
radius=100,
|
||||||
|
fade_out=True,
|
||||||
|
fade_in=True,
|
||||||
|
hold=60,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
def DoubleBouncingSpotsColorWheel(self) -> List[Effect]:
|
||||||
|
return [
|
||||||
|
BouncingSpot(bounds=self.bounds, color=color_wheel()),
|
||||||
|
BouncingSpot(bounds=self.bounds, color=color_wheel(hue=180)),
|
||||||
|
]
|
||||||
|
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
#
|
Loading…
Reference in a new issue