Added "linear_gradient".

main
Oliver Dewitz 2021-01-27 19:25:48 +01:00 zatwierdzone przez GitHub
rodzic df4a17eee3
commit 20f28a9310
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -26,6 +26,21 @@ class ws2812b:
self.sm.active(1)
self.num_leds = num_leds
self.delay = delay
# Create a gradient with two RGB colors between "pixel1" and "pixel2" (inclusive)
def linear_gradient(self, pixel1, pixel2, left_red, left_green, left_blue, right_red, right_green, right_blue):
if pixel2 - pixel1 == 0: return
right_pixel = max(pixel1, pixel2)
left_pixel = min(pixel1, pixel2)
for i in range(right_pixel - left_pixel + 1):
fraction = i / (right_pixel - left_pixel)
red = round((right_red - left_red) * fraction + left_red)
green = round((right_green - left_green) * fraction + left_green)
blue = round((right_blue - left_blue) * fraction + left_blue)
self.set_pixel(left_pixel + i, red, green, blue)
# Set an array of pixels starting from "pixel1" to "pixel2" to the desired color.
def set_pixel_line(self, pixel1, pixel2, red, green, blue):