Rain Simulation#
Inspired by https://matplotlib.org/3.2.1/gallery/animation/rain.html
[1]:
import numpy as np
import ahlive as ah
overlays = []
# have 3 unique rain occurrences
for j in np.arange(3):
arrays = []
# create 16 drops per occurrence
for i in range(np.random.randint(4, 16)):
# randomize location of raindrop splat
x = np.repeat(np.random.rand(1), 10)
y = np.repeat(np.random.rand(1), 10)
# make the raindrop splat expand in size
s = np.linspace(0, np.square(np.random.randint(50, 150)), 10)
# make the raindrop splat disappear
a = np.linspace(np.random.rand(1), 0, 10)
array = ah.Array(
x, y, s=s, alpha=a, style='bare',
facecolor='none', edgecolor='black',
legend=False, workers=4
)
arrays.append(array)
# group the raindrops into one occurrence
overlay = ah.overlay(arrays)
overlays.append(overlay)
# animate the occurrences one after another
ah.cascade(overlays).render()
[1]: