From 7555ac97fdd3cd4e92c99f01f9517d865f8c1d58 Mon Sep 17 00:00:00 2001 From: helgibbons <50950368+helgibbons@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:22:53 +0000 Subject: [PATCH] linting --- micropython/examples/plasma_stick/pulse.py | 7 ++----- micropython/examples/plasma_stick/snow.py | 7 ++++--- micropython/examples/plasma_stick/sparkles.py | 5 +++-- micropython/examples/plasma_stick/tree.py | 17 ++++++++--------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/micropython/examples/plasma_stick/pulse.py b/micropython/examples/plasma_stick/pulse.py index 99ffba1a..0c7b2af8 100644 --- a/micropython/examples/plasma_stick/pulse.py +++ b/micropython/examples/plasma_stick/pulse.py @@ -1,4 +1,3 @@ -import time import plasma from plasma import plasma_stick from math import sin @@ -27,16 +26,14 @@ while True: for i in range(NUM_LEDS): led_strip.set_hsv(i, COLOUR, 1.0, sin(offset)) offset += 0.002 - + # # our sine wave goes between -1.0 and 1.0 - this means the LEDs will be off half the time # # this formula forces the brightness to be between 0.0 and 1.0 # for i in range(NUM_LEDS): # led_strip.set_hsv(i, COLOUR, 1.0, (1 + sin(offset)) / 2) # offset += 0.002 - + # # adjust the saturation instead of the brightness/value # for i in range(NUM_LEDS): # led_strip.set_hsv(i, COLOUR, (1 + sin(offset)) / 2, 0.8) # offset += 0.002 - - diff --git a/micropython/examples/plasma_stick/snow.py b/micropython/examples/plasma_stick/snow.py index f2a47702..1a19e1b4 100644 --- a/micropython/examples/plasma_stick/snow.py +++ b/micropython/examples/plasma_stick/snow.py @@ -10,7 +10,7 @@ Adjust SNOW_INTENSITY for more snow. # Set how many LEDs you have NUM_LEDS = 50 -# How much snow? [bigger number = more snowflakes] +# How much snow? [bigger number = more snowflakes] SNOW_INTENSITY = 0.0002 # Change RGB colours here (RGB colour picker: https://g.co/kgs/k2Egjk ) @@ -27,6 +27,7 @@ def display_current(): for i in range(NUM_LEDS): led_strip.set_rgb(i, current_leds[i][0], current_leds[i][1], current_leds[i][2]) + def move_to_target(): # nudge our current colours closer to the target colours for i in range(NUM_LEDS): @@ -51,11 +52,11 @@ led_strip.start() while True: for i in range(NUM_LEDS): # randomly add snow - if SNOW_INTENSITY > uniform(0, 1): + if SNOW_INTENSITY > uniform(0, 1): # set a target to start a snowflake target_leds[i] = SNOW_COLOUR # slowly reset snowflake to background if current_leds[i] == target_leds[i]: - target_leds[i] = BACKGROUND_COLOUR + target_leds[i] = BACKGROUND_COLOUR move_to_target() # nudge our current colours closer to the target colours display_current() # display current colours to strip diff --git a/micropython/examples/plasma_stick/sparkles.py b/micropython/examples/plasma_stick/sparkles.py index 2abbb1ca..bc3cbc2a 100644 --- a/micropython/examples/plasma_stick/sparkles.py +++ b/micropython/examples/plasma_stick/sparkles.py @@ -26,6 +26,7 @@ def display_current(): for i in range(NUM_LEDS): led_strip.set_rgb(i, current_leds[i][0], current_leds[i][1], current_leds[i][2]) + def move_to_target(): # nudge our current colours closer to the target colours for i in range(NUM_LEDS): @@ -50,11 +51,11 @@ led_strip.start() while True: for i in range(NUM_LEDS): # randomly add sparkles - if SPARKLE_INTENSITY > uniform(0, 1): + if SPARKLE_INTENSITY > uniform(0, 1): # set a target to start a sparkle target_leds[i] = SPARKLE_COLOUR # for any sparkles that have achieved max sparkliness, reset them to background if current_leds[i] == target_leds[i]: - target_leds[i] = BACKGROUND_COLOUR + target_leds[i] = BACKGROUND_COLOUR move_to_target() # nudge our current colours closer to the target colours display_current() # display current colours to strip diff --git a/micropython/examples/plasma_stick/tree.py b/micropython/examples/plasma_stick/tree.py index 773d9096..a06df33c 100644 --- a/micropython/examples/plasma_stick/tree.py +++ b/micropython/examples/plasma_stick/tree.py @@ -15,11 +15,11 @@ NUM_LEDS = 50 # to convert a hue that's in degrees, divide it by 360 TREE_COLOUR = [0.34, 1.0, 0.6] LIGHT_RATIO = 8 # every nth pixel is a light, the rest are tree. -LIGHT_COLOURS = ((0.0, 1.0, 1.0), # red - (0.1, 1.0, 1.0), # orange - (0.6, 1.0, 1.0), # blue - (0.85, 0.4, 1.0)) # pink -LIGHT_CHANGE_CHANCE = 0.5 # change to 0.0 if you want static lights +LIGHT_COLOURS = ((0.0, 1.0, 1.0), # red + (0.1, 1.0, 1.0), # orange + (0.6, 1.0, 1.0), # blue + (0.85, 0.4, 1.0)) # pink +LIGHT_CHANGE_CHANCE = 0.5 # change to 0.0 if you want static lights # set up the WS2812 / NeoPixelâ„¢ LEDs led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma_stick.DAT, color_order=plasma.COLOR_ORDER_RGB) @@ -27,17 +27,16 @@ led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma_stick.DAT, color_order=plasma.C # start updating the LED strip led_strip.start() -#initial setup +# initial setup for i in range(NUM_LEDS): if i % LIGHT_RATIO == 0: # add an appropriate number of lights - led_strip.set_hsv(i, *choice(LIGHT_COLOURS)) ## choice randomly chooses from a list + led_strip.set_hsv(i, *choice(LIGHT_COLOURS)) # choice randomly chooses from a list else: # GREEN led_strip.set_hsv(i, *TREE_COLOUR) - + # animate while True: for i in range(NUM_LEDS): if (i % LIGHT_RATIO == 0) and (random() < LIGHT_CHANGE_CHANCE): led_strip.set_hsv(i, *choice(LIGHT_COLOURS)) time.sleep(0.5) -