Skip to content

Commit aa0eef2

Browse files
committed
Merge branch 'master' into bugfixes
2 parents e1d4f0d + a07c8ac commit aa0eef2

File tree

5 files changed

+442
-101
lines changed

5 files changed

+442
-101
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019-2020 Roy Hooper
4+
# Copyright (c) 2020 Kattni Rembor for Adafruit Industries
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in
14+
# all copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
# THE SOFTWARE.
23+
"""
24+
`adafruit_led_animation.animation.grid_rain`
25+
================================================================================
26+
27+
Rain animations for CircuitPython helper library for LED animations.
28+
29+
* Author(s): Roy Hooper, Kattni Rembor
30+
31+
Implementation Notes
32+
--------------------
33+
34+
**Hardware:**
35+
36+
* `Adafruit NeoPixels <https://www.adafruit.com/category/168>`_
37+
* `Adafruit DotStars <https://www.adafruit.com/category/885>`_
38+
39+
**Software and Dependencies:**
40+
41+
* Adafruit CircuitPython firmware for the supported boards:
42+
https://circuitpython.org/downloads
43+
44+
"""
45+
46+
import random
47+
from adafruit_led_animation.animation import Animation
48+
49+
__version__ = "0.0.0-auto.0"
50+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation.git"
51+
52+
from adafruit_led_animation.color import BLACK, colorwheel, calculate_intensity, GREEN
53+
54+
55+
class Rain(Animation):
56+
"""
57+
Droplets of rain.
58+
59+
:param grid_object: The initialised PixelGrid object.
60+
:param float speed: Animation speed in seconds, e.g. ``0.1``.
61+
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
62+
:param count: Number of sparkles to generate per animation cycle.
63+
:param length: Number of pixels per raindrop (Default 3)
64+
:param background: Background color (Default BLACK).
65+
"""
66+
67+
# pylint: disable=too-many-arguments
68+
def __init__(
69+
self, grid_object, speed, color, count=1, length=3, background=BLACK, name=None
70+
):
71+
self._count = count
72+
self._length = length
73+
self._background = background
74+
self._raindrops = []
75+
super().__init__(grid_object, speed, color, name=name)
76+
77+
def draw(self):
78+
79+
# Move raindrops down
80+
keep = []
81+
for raindrop in self._raindrops:
82+
pixels = []
83+
if raindrop[1][0][0] >= 0:
84+
self.pixel_object[raindrop[0], raindrop[1][0][0]] = self._background
85+
for pixel in raindrop[1]:
86+
pixel[0] += 1
87+
if pixel[0] < self.pixel_object.height:
88+
pixels.append(pixel)
89+
if pixels:
90+
keep.append([raindrop[0], pixels])
91+
self._raindrops = keep
92+
93+
# Add a raindrop
94+
if len(self._raindrops) < self._count:
95+
x = random.randint(0, self.pixel_object.width - 1)
96+
self._raindrops.append([x, self._generate_droplet(x, self._length)])
97+
98+
# Draw raindrops
99+
for x, pixels in self._raindrops:
100+
for y, color in pixels:
101+
if y >= 0:
102+
self.pixel_object[x, y] = color
103+
104+
def _generate_droplet(self, x, length): # pylint: disable=unused-argument
105+
return [[n, self.color] for n in range(-length, 0)]
106+
107+
108+
class RainbowRain(Rain):
109+
"""
110+
Rainbow Rain animation.
111+
"""
112+
113+
def __init__( # pylint: disable=too-many-arguments
114+
self, grid_object, speed, count=1, length=3, background=BLACK, name=None
115+
):
116+
super().__init__(grid_object, speed, BLACK, count, length, background, name)
117+
118+
def _generate_droplet(self, x, length):
119+
color = colorwheel(random.randint(0, 255))
120+
return [
121+
[n, calculate_intensity(color, 1.0 - -((n + 1) / (length + 1)))]
122+
for n in range(-length, 0)
123+
]
124+
125+
126+
class MatrixRain(Rain):
127+
"""
128+
The Matrix style animation.
129+
"""
130+
131+
def __init__( # pylint: disable=too-many-arguments
132+
self,
133+
grid_object,
134+
speed,
135+
color=GREEN,
136+
count=1,
137+
length=6,
138+
background=(0, 32, 0),
139+
name=None,
140+
):
141+
super().__init__(grid_object, speed, color, count, length, background, name)
142+
143+
def _generate_droplet(self, x, length):
144+
return [
145+
[n, calculate_intensity(self.color, random.randint(10, 100) * 1.0)]
146+
for n in range(-length, 0)
147+
]

adafruit_led_animation/animation/pulse.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,11 @@ def reset(self):
7474
"""
7575
Resets the animation.
7676
"""
77-
white = len(self.pixel_object[0]) > 3 and isinstance(
78-
self.pixel_object[0][-1], int
79-
)
8077
dotstar = len(self.pixel_object[0]) == 4 and isinstance(
8178
self.pixel_object[0][-1], float
8279
)
8380
from adafruit_led_animation.helper import ( # pylint: disable=import-outside-toplevel
8481
pulse_generator,
8582
)
8683

87-
self._generator = pulse_generator(
88-
self._period, self, white, dotstar_pwm=dotstar
89-
)
84+
self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar)

adafruit_led_animation/animation/sparklepulse.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ def __init__(
7474
self._max_intensity = max_intensity
7575
self._min_intensity = min_intensity
7676
self._period = period
77-
white = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], int)
7877
dotstar = len(pixel_object) == 4 and isinstance(pixel_object[0][-1], float)
7978
super().__init__(
8079
pixel_object, speed=speed, color=color, num_sparkles=1, name=name
8180
)
82-
self._generator = pulse_generator(
83-
self._period, self, white, dotstar_pwm=dotstar
84-
)
81+
self._generator = pulse_generator(self._period, self, dotstar_pwm=dotstar)
8582

8683
def draw(self):
8784
self._sparkle_color = next(self._generator)

0 commit comments

Comments
 (0)