Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zherit spectrum colour mod #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,36 @@

MIN_VOLUME_THRESHOLD = 1e-7
"""No music visualization displayed if recorded audio volume below threshold"""


#OPTIONS FOR SPECTRUM MODE COLOURS

"""
These are the options for the spectrum colour mode added by Zherit

SPEC_ORDER can be any combination of the letters r, g, and b written as "xyz"
where x is the priority colour, y is the secondary, and z is tertiary. You must
have unique entries for x y and z ie. "rrb" will NOT work. You can also enter
"rand" for the colours to be randomized.

RAND_MODE can be set to "random" or "wheel" depending on if you want a truly
random colour sequence or you would like to cycle through all options one
at a time. *NOTE: SPEC_ORDER must be set to "rand" for this to work

RAND_FREQ sets the frequency at which to change the colours in "rand" mode.
It is based off of FPS so if your FPS is set to 50 then changing colours
every half second would be RAND_FREQ = 25. *NOTE: SPEC_ORDER must be set to
"rand" for this to work

RAND_NUM and CYCLE_COUNT are used by the program as variables. DO NOT TOUCH THESE


"""
SPEC_ORDER = "bgr"
RAND_MODE = "wheel"
RAND_FREQ = 15


#DO NOT TOUCH
RAND_NUM = 0
CYCLE_COUNT = 0
73 changes: 66 additions & 7 deletions python/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dsp
import led
import sys
from random import randrange

visualization_type = sys.argv[1]

Expand All @@ -20,15 +21,12 @@

def frames_per_second():
"""Return the estimated frames per second

Returns the current estimate for frames-per-second (FPS).
FPS is estimated by measured the amount of time that has elapsed since
this function was previously called. The FPS estimate is low-pass filtered
to reduce noise.

This function is intended to be called one time for every iteration of
the program's main loop.

Returns
-------
fps : float
Expand Down Expand Up @@ -67,15 +65,12 @@ def _normalized_linspace(size):

def interpolate(y, new_length):
"""Intelligently resizes the array by linearly interpolating the values

Parameters
----------
y : np.array
Array that should be resized

new_length : int
The length of the new interpolated array

Returns
-------
z : np.array
Expand Down Expand Up @@ -175,7 +170,71 @@ def visualize_spectrum(y):
r = np.concatenate((r[::-1], r))
g = np.concatenate((g[::-1], g))
b = np.concatenate((b[::-1], b))
output = np.array([r, g,b]) * 255

#Code for randomizing the colour of the spectrum
primary = b
secondary = g
tertiary = r
config_mode = config.SPEC_ORDER


if config.CYCLE_COUNT == 0:
#Set if random mode is truly random or cycles through colours in order
if config.RAND_MODE == "random":
config.RAND_NUM = randrange(5)
elif config.RAND_MODE == "wheel":
if config.RAND_NUM >= 5:
config.RAND_NUM = 0
else:
config.RAND_NUM += 1
config.CYCLE_COUNT += 1
elif config.CYCLE_COUNT >= config.RAND_FREQ:
config.CYCLE_COUNT = 0
else:
config.CYCLE_COUNT += 1

#If SPEC_ORDER is set to "rand"
if config.SPEC_ORDER == "rand":
if config.RAND_NUM == 0:
config_mode = "rgb"
elif config.RAND_NUM == 1:
config_mode = "rgb"
elif config.RAND_NUM == 2:
config_mode = "grb"
elif config.RAND_NUM == 3:
config_mode = "gbr"
elif config.RAND_NUM == 4:
config_mode = "bgr"
elif config.RAND_NUM == 5:
config_mode = "brg"

#If SPEC_ORDER is set via rgb (in any combination)
if config_mode == "rbg":
primary = r
secondary = b
tertiary = b
elif config_mode == "rgb":
primary = r
secondary = g
tertiary = b
elif config_mode == "grb":
primary = g
secondary = r
tertiary = b
elif config_mode == "gbr":
primary = g
secondary = b
tertiary = r
elif config_mode == "bgr":
primary = b
secondary = g
tertiary = r
elif config_mode == "brg":
primary = b
secondary = r
tertiary = g

output = np.array([tertiary, secondary, primary]) * 255
return output


Expand Down