7 DISPLAY_ANIMATION_SPEED
= 500 # Add this line
9 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
, first
=0, last
=NP_COUNT
, fade_by
=0.9):
20 for i
in range(first
, last
):
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
)
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
35 , first
=(NP_COUNT
- BURST_SIZE
- i
)
36 , last
= (NP_COUNT
- BURST_SIZE
+ 1)
40 fade_all(pixels
, first
=(NP_COUNT
- 2 * BURST_SIZE
))
43 for n
in range(NP_COUNT
):
47 display
.show(Image
.DIAMOND
) # Add this line
50 def shoot_firework(pixels
):
51 display
.show(Image
.ARROW_S
) # Add this line
52 for pixel
in range(NP_COUNT
- BURST_SIZE
):
61 display_timer
= 0 # Add this line
62 last_gesture
= accelerometer
.current_gesture()
65 gesture
= accelerometer
.current_gesture()
66 if gesture
!= last_gesture
or button_a
.is_pressed():
71 last_gesture
= gesture
73 #########################################
77 display_timer
= (display_timer
+ 1) % DISPLAY_ANIMATION_SPEED
78 if display_timer
> (DISPLAY_ANIMATION_SPEED
/ 2):
79 display
.show(Image
.DIAMOND_SMALL
)
81 display
.show(Image
.DIAMOND
)
83 #########################################