8 np
= neopixel
.NeoPixel(pin0
, NP_COUNT
)
14 FIREWORK_COLOURS
= [ (255, 128, 128), (128, 255, 128), (128, 128, 255)
15 , (255, 255, 128), (255, 128, 255), (128, 255, 255)
18 def fade_all(pixels
, first
=0, last
=NP_COUNT
, fade_by
=0.9): # Change this line
19 for i
in range(first
, last
): # Change this line
20 fade(pixels
, i
, fade_by
=fade_by
)
23 def fade(pixels
, n
, fade_by
=0.9):
25 pixels
[n
] = (int(r
* fade_by
), int(g
* fade_by
), int(b
* fade_by
))
28 initial_colour
= random
.choice(FIREWORK_COLOURS
)
30 for i
in range(BURST_SIZE
):
31 pixels
[NP_COUNT
- BURST_SIZE
+ i
] = initial_colour
32 pixels
[NP_COUNT
- BURST_SIZE
- i
] = initial_colour
33 fade_all( pixels
, fade_by
=0.95 # Change this line
34 , first
=(NP_COUNT
- BURST_SIZE
- i
) # Add this line
35 , last
= (NP_COUNT
- BURST_SIZE
+ 1) # Add this line
39 fade_all(pixels
, first
=(NP_COUNT
- 2 * BURST_SIZE
)) # Change this line
42 for n
in range(NP_COUNT
):
47 def shoot_firework(pixels
):
48 for pixel
in range(NP_COUNT
- BURST_SIZE
):
57 last_gesture
= accelerometer
.current_gesture()
60 gesture
= accelerometer
.current_gesture()
61 if gesture
!= last_gesture
or button_a
.is_pressed():
66 last_gesture
= gesture