diff --git a/python/config.py b/python/config.py index 65e21378..da1f99c4 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 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 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