4
4
# -----------------------------------------------------------------------------
5
5
import matplotlib
6
6
import numpy as np
7
- matplotlib .use ('TkAgg' )
8
- matplotlib .rcParams ['toolbar' ] = 'None'
7
+ matplotlib .use ('TkAgg' ) # Required on OSX for animation
9
8
import matplotlib .pyplot as plt
10
9
from matplotlib .animation import FuncAnimation
11
10
12
11
13
12
# Create new figure
14
13
fig = plt .figure (figsize = (7 ,7 ))
15
- fig .patch .set_facecolor ('white' )
16
14
ax = fig .add_axes ([0 ,0 ,1 ,1 ], frameon = False , aspect = 1 )
17
15
18
16
# Create rain data
23
21
24
22
# Scatter plot is used to animate rain drops
25
23
scat = ax .scatter (P ['position' ][:,0 ], P ['position' ][:,1 ], P ['size' ], lw = 0.5 ,
26
- animated = True , edgecolors = P ['color' ], facecolors = 'None ' )
24
+ animated = True , edgecolors = P ['color' ], facecolors = 'none ' )
27
25
ax .set_xlim (0 ,1 ), ax .set_xticks ([])
28
26
ax .set_ylim (0 ,1 ), ax .set_yticks ([])
29
27
@@ -32,22 +30,23 @@ def update(frame):
32
30
i = frame % len (P )
33
31
34
32
# Make all colors more transparent
35
- P ['color' ][:,3 ] = np .maximum (0 , P ['color' ][:,3 ] - 1.0 / len (P ))
33
+ P ['color' ][:,3 ] -= 1.0 / len (P )
34
+ P ['color' ][:,3 ] = np .clip (P ['color' ][:,3 ], 0 , 1 )
36
35
37
36
# Make all circles bigger
38
37
P ['size' ] += P ['growth' ]
39
38
40
39
# Pick a new position for oldest rain drop
41
- P ['position' ][i ] = np .random .uniform (0 ,1 , 2 )
40
+ P ['position' ][i ] = np .random .uniform (0 , 1 , 2 )
42
41
43
42
# Reset size
44
- P ['size' ][i ] = 5
43
+ P ['size' ][i ] = 5
45
44
46
45
# Reset color
47
- P ['color' ][i ] = 0 , 0 , 0 , 1
46
+ P ['color' ][i ] = ( 0 , 0 , 0 , 1 )
48
47
49
48
# Choose a random growth factor
50
- P ['growth' ][i ] = np .random .uniform (50 ,200 )
49
+ P ['growth' ][i ] = np .random .uniform (50 , 200 )
51
50
52
51
# Update scatter plot
53
52
scat .set_edgecolors (P ['color' ])
0 commit comments