3 import random
# Add this line
8 np
= neopixel
.NeoPixel(pin0
, NP_COUNT
)
15 FIREWORK_COLOURS
= [ (255, 128, 128), (128, 255, 128), (128, 128, 255)
16 , (255, 255, 128), (255, 128, 255), (128, 255, 255)
19 def fade_all(pixels
, fade_by
=0.9):
20 for i
in range(NP_COUNT
):
21 fade(pixels
, i
, fade_by
=fade_by
)
24 def fade(pixels
, n
, fade_by
=0.9):
26 pixels
[n
] = (int(r
* fade_by
), int(g
* fade_by
), int(b
* fade_by
))
29 initial_colour
= random
.choice(FIREWORK_COLOURS
) # Change this line
31 for i
in range(BURST_SIZE
):
32 pixels
[NP_COUNT
- BURST_SIZE
+ i
] = initial_colour
33 pixels
[NP_COUNT
- BURST_SIZE
- i
] = initial_colour
34 fade_all(pixels
, fade_by
=0.95) # Add this line
40 for n
in range(NP_COUNT
):
45 def shoot_firework(pixels
):
46 for pixel
in range(NP_COUNT
- BURST_SIZE
):
55 last_gesture
= accelerometer
.current_gesture()
58 gesture
= accelerometer
.current_gesture()
59 if gesture
!= last_gesture
or button_a
.is_pressed():
64 last_gesture
= gesture