From beaf70f08445fcfd6ddfac79763f7610e5b61f87 Mon Sep 17 00:00:00 2001 From: Zherit <41634017+Zherit@users.noreply.github.com> Date: Sat, 25 Sep 2021 14:13:09 -0400 Subject: [PATCH 1/4] SPECTRUM colour mode options Added configuration options for the spectrum colour mode modification. --- python/config.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/python/config.py b/python/config.py index 65e21378..4bbbbb82 100644 --- a/python/config.py +++ b/python/config.py @@ -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 z is the priority colour, y is the secondary, and x 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 = "rand" +RAND_MODE = "wheel" +RAND_FREQ = 15 + + +#DO NOT TOUCH +RAND_NUM = 0 +CYCLE_COUNT = 0 From 12f5f453603654506f1cc448272db0eed384c10d Mon Sep 17 00:00:00 2001 From: Zherit <41634017+Zherit@users.noreply.github.com> Date: Sat, 25 Sep 2021 14:43:16 -0400 Subject: [PATCH 2/4] Update visualization.py --- python/visualization.py | 73 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/python/visualization.py b/python/visualization.py index 4802299d..1fca769e 100644 --- a/python/visualization.py +++ b/python/visualization.py @@ -8,6 +8,7 @@ import dsp import led import sys +from random import randrange visualization_type = sys.argv[1] @@ -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 @@ -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 @@ -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 From 6cac091fc43772e5642050e9c2a4ce70c6a27997 Mon Sep 17 00:00:00 2001 From: Zherit <41634017+Zherit@users.noreply.github.com> Date: Sat, 25 Sep 2021 14:50:37 -0400 Subject: [PATCH 3/4] Update config.py Changed the default configuration so that it behaves as it would without the colour cycle mod (so that users don't start with it activated) --- python/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/config.py b/python/config.py index 4bbbbb82..11cbef6c 100644 --- a/python/config.py +++ b/python/config.py @@ -128,7 +128,7 @@ """ -SPEC_ORDER = "rand" +SPEC_ORDER = "bgr" RAND_MODE = "wheel" RAND_FREQ = 15 From 3ecf15ef2b89349ff4baabac316b0b9d74a910ee Mon Sep 17 00:00:00 2001 From: Zherit <41634017+Zherit@users.noreply.github.com> Date: Sat, 25 Sep 2021 14:51:56 -0400 Subject: [PATCH 4/4] Update config.py --- python/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/config.py b/python/config.py index 11cbef6c..da1f99c4 100644 --- a/python/config.py +++ b/python/config.py @@ -111,7 +111,7 @@ 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 z is the priority colour, y is the secondary, and x is tertiary. You must +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.