-
Notifications
You must be signed in to change notification settings - Fork 2
/
smooth_rainbow_animation.py
62 lines (47 loc) · 1.26 KB
/
smooth_rainbow_animation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from adafruit_circuitplayground.express import cpx
from time import sleep
import random
#cpx.pixels.brightness = 0.1
violet = (255,0,255)
indigo = (147,0,255)
blue = (0,0,255)
green = (0,255,0)
yellow = (255,255,0)
orange = (255,174,66)
red = (255,0,0)
colors = [indigo,blue,green,yellow,orange,red,violet]
def change(color_1,color_2,speed=1):
color_1 = list(color_1)
if color_1[0] > color_2[0]:
color_1[0] -= speed
if color_1[0] < color_2[0]:
color_1[0] += speed
if color_1[1] > color_2[1]:
color_1[1] -= speed
if color_1[1] < color_2[1]:
color_1[1] += speed
if color_1[2] > color_2[2]:
color_1[2] -= speed
if color_1[2] < color_2[2]:
color_1[2] += speed
if color_1[0] > 255:
color_1[0] = 255
if color_1[0] < 0:
color_1[0] = 0
if color_1[1] > 255:
color_1[1] = 255
if color_1[1] < 0:
color_1[1] = 0
if color_1[2] > 255:
color_1[2] = 255
if color_1[2] < 0:
color_1[2] = 0
return tuple(color_1)
while True:
color_1 = violet
for x in colors:
color_2 = x
#print(color_1, "->", color_2)
while color_1 != color_2:
cpx.pixels.fill(color_1)
color_1 = change(color_1,color_2)