From 9209ef73aed9c898ba4420646fa042c0352f4820 Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Thu, 18 Nov 2021 18:32:37 +0100 Subject: [PATCH] Minor refactorings --- scripting/CyanLightSparkling.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/scripting/CyanLightSparkling.py b/scripting/CyanLightSparkling.py index 90be8b0..a2f84fc 100755 --- a/scripting/CyanLightSparkling.py +++ b/scripting/CyanLightSparkling.py @@ -7,29 +7,44 @@ import random from socket import * +fps = 4 +pixels = 24 +port = 4213 + +randomizeBrightness = False + + if len(sys.argv) > 1: hosts = sys.argv[1:] else: hosts = ['ringclockDOTmake', 'ringclockDOThack', 'ringclockDOTelab'] -port = 4213 - -pixels = 24 - s = socket(AF_INET, SOCK_DGRAM) - def cyan(): r = random.randint(0, 32) g = random.randint(64, 255) - return [r, g, int(g/6), 0] + out = [r, g, int(g/6), 0] + + if randomizeBrightness: + b = random.random() + out = [ int(px * b) for px in out ] + return out + + +period = 1 / fps while True: - data = [1] +# if fps >= 10: +# data = [1] +# else: +# data = [int( 50 * period )] + + data = [int( 50 * period )] for _ in range(pixels): data += cyan() @@ -40,5 +55,5 @@ while True: s.sendto(data, (host, port)) except: pass - time.sleep(0.1) + time.sleep(period) -- GitLab