mirror of
https://github.com/correl/turntable.git
synced 2024-11-23 19:19:55 +00:00
Make colors configurable
This commit is contained in:
parent
6194cfcd49
commit
e859e021de
2 changed files with 25 additions and 9 deletions
|
@ -35,6 +35,12 @@
|
||||||
},
|
},
|
||||||
"gui": {
|
"gui": {
|
||||||
"width": 1280,
|
"width": 1280,
|
||||||
"height": 720
|
"height": 720,
|
||||||
|
"bars": [
|
||||||
|
[ 0, [ 0, 255, 0]],
|
||||||
|
[50, [255, 255, 0]],
|
||||||
|
[75, [255, 0, 0]]
|
||||||
|
],
|
||||||
|
"lines": [100, 100, 100]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ class Plot:
|
||||||
width: int,
|
width: int,
|
||||||
height: int,
|
height: int,
|
||||||
bars: int = 20,
|
bars: int = 20,
|
||||||
|
bar_colors: List[Tuple[int, Tuple[int, int, int]]] = [
|
||||||
|
(0, (255, 255, 255)),
|
||||||
|
],
|
||||||
|
lines_color: Tuple[int, int, int] = (128, 128, 128),
|
||||||
) -> None:
|
) -> None:
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
self.x = x
|
self.x = x
|
||||||
|
@ -32,6 +36,8 @@ class Plot:
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.bars = bars
|
self.bars = bars
|
||||||
|
self.bar_colors = bar_colors
|
||||||
|
self.lines_color = lines_color
|
||||||
self.audio = models.PCM(44100, 2)
|
self.audio = models.PCM(44100, 2)
|
||||||
|
|
||||||
def spectrum(self) -> np.array:
|
def spectrum(self) -> np.array:
|
||||||
|
@ -60,7 +66,7 @@ class Plot:
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
pygame.draw.line(
|
pygame.draw.line(
|
||||||
self.screen,
|
self.screen,
|
||||||
(128, 128, 128),
|
self.lines_color,
|
||||||
(self.x + i * 4, self.height),
|
(self.x + i * 4, self.height),
|
||||||
(self.x + i * 4, self.height - int(line)),
|
(self.x + i * 4, self.height - int(line)),
|
||||||
)
|
)
|
||||||
|
@ -81,13 +87,8 @@ class Plot:
|
||||||
light_steps = self.height // light_height // 2
|
light_steps = self.height // light_height // 2
|
||||||
lights = fft * light_steps / 100
|
lights = fft * light_steps / 100
|
||||||
|
|
||||||
colors = [
|
color_keys = [k for k, v in self.bar_colors]
|
||||||
(0, (0, 255, 0)),
|
color_values = [v for k, v in self.bar_colors]
|
||||||
(50, (255, 255, 0)),
|
|
||||||
(75, (255, 0, 0)),
|
|
||||||
]
|
|
||||||
color_keys = [k for k, v in colors]
|
|
||||||
color_values = [v for k, v in colors]
|
|
||||||
for i, steps in enumerate(lights):
|
for i, steps in enumerate(lights):
|
||||||
for step in range(int(steps)):
|
for step in range(int(steps)):
|
||||||
color = color_values[bisect(color_keys, step / light_steps * 100) - 1]
|
color = color_values[bisect(color_keys, step / light_steps * 100) - 1]
|
||||||
|
@ -153,6 +154,15 @@ def main():
|
||||||
width=screen.get_width(),
|
width=screen.get_width(),
|
||||||
height=screen.get_height() - 50,
|
height=screen.get_height() - 50,
|
||||||
bars=15,
|
bars=15,
|
||||||
|
bar_colors=config.get(
|
||||||
|
"bars",
|
||||||
|
[
|
||||||
|
(0, (0, 255, 0)),
|
||||||
|
(50, (255, 255, 0)),
|
||||||
|
(75, (255, 0, 0)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
lines_color=config.get("lines", (128, 128, 128)),
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue