revert flatten changes for now
added rainbow colors, based on rainbow mod (no sync yet)
This commit is contained in:
parent
26b6dd02c7
commit
fb5000139a
@ -13,6 +13,7 @@ import numpy as np
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
# get screen size from parameters
|
# get screen size from parameters
|
||||||
Nx = 80
|
Nx = 80
|
||||||
@ -40,8 +41,10 @@ except:
|
|||||||
class Layer:
|
class Layer:
|
||||||
def __init__(self, new_path):
|
def __init__(self, new_path):
|
||||||
self.path = new_path
|
self.path = new_path
|
||||||
# read png file and get gray scale map as 3 dimension rgb array
|
# read png file
|
||||||
self.gray_scale_map_small_direct = png.Reader(self.path).asRGB8()
|
self.png_reader = png.Reader(self.path)
|
||||||
|
# gray_scale_map_small = png_reader.read()
|
||||||
|
self.gray_scale_map_small_direct = self.png_reader.asRGB8()
|
||||||
# get png data from png object
|
# get png data from png object
|
||||||
self.png_width = self.gray_scale_map_small_direct[0]
|
self.png_width = self.gray_scale_map_small_direct[0]
|
||||||
self.png_height = self.gray_scale_map_small_direct[1]
|
self.png_height = self.gray_scale_map_small_direct[1]
|
||||||
@ -52,11 +55,16 @@ class Layer:
|
|||||||
self.rgb_buffer_length = (self.png_width * self.png_height) * self.color_values
|
self.rgb_buffer_length = (self.png_width * self.png_height) * self.color_values
|
||||||
self.layer_buffer_current_color = np.zeros(self.color_values, np.uint8)
|
self.layer_buffer_current_color = np.zeros(self.color_values, np.uint8)
|
||||||
self.layer_buffer_array = np.zeros(self.rgb_buffer_length, np.uint8)
|
self.layer_buffer_array = np.zeros(self.rgb_buffer_length, np.uint8)
|
||||||
self.png_image_data_flatten = np.array(self.png_image_data).flatten()
|
self.png_image_data_flatten = np.array(self.flatten_rgb_array_from_png(self.png_image_data))
|
||||||
# internal event states
|
# internal event states
|
||||||
self.layer_current_event_value = 0
|
self.layer_current_event_value = 0
|
||||||
self.animation_finished = True
|
self.animation_finished = True
|
||||||
self.animation_current_brightness = self.max_brightness
|
self.animation_current_brightness = self.max_brightness
|
||||||
|
# rainbow stuff :D
|
||||||
|
self.rainbow_mode = False
|
||||||
|
self.color_random_min = 15
|
||||||
|
self.color_random_max = 31
|
||||||
|
self.color_random_mult = 8
|
||||||
# just debug stuff
|
# just debug stuff
|
||||||
# print("created layer for " + self.path)
|
# print("created layer for " + self.path)
|
||||||
|
|
||||||
@ -72,7 +80,7 @@ class Layer:
|
|||||||
def run_next_fade_color(self):
|
def run_next_fade_color(self):
|
||||||
if not self.animation_finished and self.animation_current_brightness > 0:
|
if not self.animation_finished and self.animation_current_brightness > 0:
|
||||||
# fade rgb values
|
# fade rgb values
|
||||||
self.animation_current_brightness -= 25
|
self.animation_current_brightness -= 1
|
||||||
|
|
||||||
# set current layer color brightness to animation brightness
|
# set current layer color brightness to animation brightness
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
@ -118,6 +126,14 @@ class Layer:
|
|||||||
output_rgb_array[1] = self.max_brightness
|
output_rgb_array[1] = self.max_brightness
|
||||||
self.animation_finished = True
|
self.animation_finished = True
|
||||||
|
|
||||||
|
if self.rainbow_mode and event_value != 0 and event_value != 8:
|
||||||
|
output_rgb_array[0] = np.uint8(random.randint(self.color_random_min,
|
||||||
|
self.color_random_max) * self.color_random_mult)
|
||||||
|
output_rgb_array[1] = np.uint8(random.randint(self.color_random_min,
|
||||||
|
self.color_random_max) * self.color_random_mult)
|
||||||
|
output_rgb_array[2] = np.uint8(random.randint(self.color_random_min,
|
||||||
|
self.color_random_max) * self.color_random_mult)
|
||||||
|
|
||||||
return output_rgb_array
|
return output_rgb_array
|
||||||
|
|
||||||
def render_rgb_layer(self, r=0, g=0, b=0):
|
def render_rgb_layer(self, r=0, g=0, b=0):
|
||||||
@ -139,6 +155,19 @@ class Layer:
|
|||||||
# print("new_color: " + str(current_value) + ":" + str(mapping_value) + "=" + str(new_value))
|
# print("new_color: " + str(current_value) + ":" + str(mapping_value) + "=" + str(new_value))
|
||||||
return new_value
|
return new_value
|
||||||
|
|
||||||
|
# helper method to flatted the png array payload, called only once on init
|
||||||
|
def flatten_rgb_array_from_png(self, rgb_array):
|
||||||
|
output_array = np.zeros(self.rgb_buffer_length, np.uint8)
|
||||||
|
current_value_index = 0
|
||||||
|
# got over every row of png
|
||||||
|
for current_row in rgb_array:
|
||||||
|
# go over value in payload
|
||||||
|
for current_value in current_row:
|
||||||
|
# write current value to output array buffer
|
||||||
|
output_array[current_value_index] = current_value
|
||||||
|
current_value_index += 1
|
||||||
|
return output_array
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------
|
# ------------------------------------
|
||||||
# Websocket event part start
|
# Websocket event part start
|
||||||
|
Loading…
Reference in New Issue
Block a user