pride.py 4.39 KB
Newer Older
fleur's avatar
fleur committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
flags = {}
flags["rainbow"] = [
    [255, 0, 24],
    [255, 165, 44],
    [255, 255, 65],
    [0, 128, 24],
    [0, 0, 249],
    [134, 0, 125],
]
flags["trans"] = [
    [85, 205, 252],
    [247, 168, 184],
    [255, 255, 255],
    [247, 168, 184],
    [85, 205, 252],
]
17
flags["bi"] = [[214, 2, 112], [214, 2, 112], [155, 79, 150], [0, 56, 168], [0, 56, 168]]
fleur's avatar
fleur committed
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
flags["ace"] = [[1, 1, 1], [164, 164, 164], [255, 255, 255], [150, 0, 150]]
flags["greyace"] = [
    [150, 0, 150],
    [164, 164, 164],
    [255, 255, 255],
    [164, 164, 164],
    [150, 0, 150],
]
flags["aro"] = [
    [61, 165, 66],
    [167, 211, 121],
    [255, 255, 255],
    [169, 169, 169],
    [1, 1, 1],
]
flags["greyaro"] = [
    [61, 165, 66],
    [164, 164, 164],
    [255, 255, 255],
    [164, 164, 164],
    [61, 165, 66],
]
flags["pan"] = [[255, 27, 141], [255, 218, 0], [27, 179, 255]]
flags["inter"] = [[255, 218, 0], [122, 0, 172]]
flags["genderqueer"] = [[201, 138, 255], [255, 255, 255], [80, 150, 85]]
flags["lesbian"] = [
    [139, 60, 105],
    [171, 99, 143],
    [187, 127, 179],
    [255, 255, 255],
    [228, 172, 207],
    [214, 113, 113],
    [134, 70, 70],
]
flags["nonbinary"] = [[255, 244, 51], [255, 255, 255], [155, 89, 208], [0, 0, 0]]
flags["genderfluid"] = [
    [254, 117, 161],
    [255, 255, 255],
    [189, 22, 213],
    [0, 0, 0],
    [50, 61, 187],
]
flags["agender"] = [
    [0, 0, 0],
    [150, 150, 150],
    [255, 255, 255],
    [182, 245, 131],
    [255, 255, 255],
    [150, 150, 150],
    [0, 0, 0],
]
flags["poly"] = [
    [0, 0, 255],
    [0, 0, 255],
    [0, 0, 255],
    [255, 0, 0],
    [255, 0, 0],
    [255, 255, 0],
    [255, 0, 0],
    [255, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
    [0, 0, 0],
]
import leds, display, math, utime, ledfx


def expand(colors, cutoff=12):
fleur's avatar
fleur committed
86
87
88
89
90
91
    """
    Expands the raw color list to a longer list, for example for the 11 LEDs.

    :param int colors: Color list to be expanded.
    :param int cutoff: How long the expanded list is to be. Default = 12
    """
fleur's avatar
fleur committed
92
93
94
95
96
97
98
99
100
101
102
103
    output = []
    if len(colors) != 7 or cutoff > 14:
        leds_per_color = int(cutoff / len(colors))
        for i in colors:
            output += [i] * leds_per_color
    else:
        for j, i in enumerate(colors):
            output += [i] * (1 + (j % 2 == 1))
    return output


def show_leds(flag="rainbow", brightness=0.5, gamma=1, cutoff=12, halo=True):
fleur's avatar
fleur committed
104
105
    """
    Shows pride flag on the top leds.
Rahix's avatar
Rahix committed
106

fleur's avatar
fleur committed
107
108
109
    :param str flag: Chooses flag. A list of all available flags is accessible
        via print_all(). Default = 'rainbow'
    :param float brightness: Set brightness of LEDs. Default = 0.5
Rahix's avatar
Rahix committed
110
    :param float gamma: Apply simple gamma correction to adjust colors.
fleur's avatar
fleur committed
111
112
        Default = 1
    :param int cutoff: See expand(). Default = 12
Rahix's avatar
Rahix committed
113
    :param bool halo: Bottom LEDs copy outermost top LEDs if true.
fleur's avatar
fleur committed
114
115
        Default = True
    """
fleur's avatar
fleur committed
116
117
118
119
120
121
122
123
124
    colors = ledfx.col_cor(flags[flag], brightness, gamma)
    output = expand(colors, cutoff)[::-1][0:11]
    if halo:
        output = ledfx.halo(output)
    leds.clear()
    leds.set_all(output)


def show_display(flag="rainbow", brightness=1, gamma=1):
fleur's avatar
fleur committed
125
126
    """
    Shows pride flag on the display.
Rahix's avatar
Rahix committed
127

fleur's avatar
fleur committed
128
129
130
131
132
133
    :param str flag: Chooses flag. A list of all available flags is accessible
        via print_all(). Default = 'rainbow'
    :param float brightness: Set brightness of LEDs. Default = 0.5
    :param float gamma: Apply simple gamma correction to adjust colors.
        Default = 1
    """
fleur's avatar
fleur committed
134
135
136
137
138
139
140
141
142
143
144
    colors = ledfx.col_cor(flags[flag], brightness, gamma)
    colors = expand(colors, 160)
    with display.open() as disp:
        disp.clear()
        for line, color in enumerate(colors):
            disp.line(line, 0, line, 80, col=color)
        disp.update()
        disp.close()


def get(flag="rainbow"):
fleur's avatar
fleur committed
145
146
147
148
149
150
    """
    Returns color list of flag.

    :param str flag: Chooses flag. A list of all available flags is accessible
        via print_all(). Default = 'rainbow'
    """
fleur's avatar
fleur committed
151
152
153
    return flags[flag]


fleur's avatar
fleur committed
154
155
156
157
158
159
160
161
def print_all():
    """
    Prints the names of all available flags on the serial port.
    """
    for i in flags:
        print(i)


fleur's avatar
fleur committed
162
def demo(s_delay=2):
fleur's avatar
fleur committed
163
164
    """
    Demos all available flags on LEDs and display.
Rahix's avatar
Rahix committed
165

fleur's avatar
fleur committed
166
167
    :param int s_delay: How long each flag is shown in seconds. Default = 2
    """
fleur's avatar
fleur committed
168
169
170
171
172
173
174
175
176
    for i in flags:
        print(i)
        show_leds(flag=i)
        show_display(flag=i)
        utime.sleep_ms(s_delay * 1000)
    leds.clear()
    with display.open() as disp:
        disp.clear().update()
        disp.close()