Skip to content

Commit bbbc07a

Browse files
committed
add rounded corners
1 parent cee593c commit bbbc07a

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

docs/logo_animated.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,32 @@
33
from matplotlib import animation
44
from matplotlib import pyplot as plt
55
from matplotlib.animation import FFMpegWriter
6+
from PIL import Image, ImageDraw
67
from tqdm.auto import tqdm
78

89
import adaptive
910

1011

12+
def add_rounded_corners(size, rad):
13+
# Make new images
14+
circle = Image.new("L", (rad * 2, rad * 2), 1)
15+
draw = ImageDraw.Draw(circle)
16+
draw.ellipse((0, 0, rad * 2, rad * 2), fill=0)
17+
alpha = Image.new("L", size, 0)
18+
19+
# Crop circles
20+
w, h = size
21+
alpha.paste(circle.crop((0, 0, rad, rad)), (0, 0))
22+
alpha.paste(circle.crop((0, rad, rad, rad * 2)), (0, h - rad))
23+
alpha.paste(circle.crop((rad, 0, rad * 2, rad)), (w - rad, 0))
24+
alpha.paste(circle.crop((rad, rad, rad * 2, rad * 2)), (w - rad, h - rad))
25+
26+
# To array
27+
cut = np.array(alpha).astype(float)
28+
cut[cut == 0] = np.nan
29+
return cut
30+
31+
1132
def learner_till(till, learner, data):
1233
new_learner = adaptive.Learner2D(None, bounds=learner.bounds)
1334
new_learner.data = {k: v for k, v in data[:till]}
@@ -23,12 +44,15 @@ def plot_tri(learner, ax):
2344
return ax.triplot(triang, c="k", lw=0.8, alpha=0.8)
2445

2546

26-
def get_new_artists(npoints, learner, data):
47+
def get_new_artists(npoints, learner, data, rounded_corners, ax):
2748
new_learner = learner_till(npoints, learner, data)
2849
line1, line2 = plot_tri(new_learner, ax)
2950
data = np.rot90(new_learner.interpolated_on_grid()[-1])
3051
im = ax.imshow(data, extent=(-0.5, 0.5, -0.5, 0.5), cmap="viridis")
31-
return im, line1, line2
52+
im2 = ax.imshow(
53+
rounded_corners, extent=(-0.5, 0.5, -0.5, 0.5), cmap="gray_r", zorder=10
54+
)
55+
return im, line1, line2, im2
3256

3357

3458
def create_and_run_learner():
@@ -53,11 +77,17 @@ def ring(xy):
5377
fig.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=None, hspace=None)
5478
ax.set_xticks([])
5579
ax.set_yticks([])
80+
ax.spines["top"].set_visible(False)
81+
ax.spines["right"].set_visible(False)
82+
ax.spines["bottom"].set_visible(False)
83+
ax.spines["left"].set_visible(False)
5684

5785
nseconds = 15
5886
npoints = (len(data) * np.linspace(0, 1, 24 * nseconds) ** 2).astype(int)
59-
60-
artists = [get_new_artists(n, learner, data) for n in tqdm(npoints)]
87+
rounded_corners = add_rounded_corners(size=(1000, 1000), rad=300)
88+
artists = [
89+
get_new_artists(n, learner, data, rounded_corners, ax) for n in tqdm(npoints)
90+
]
6191

6292
ani = animation.ArtistAnimation(fig, artists, blit=True)
63-
ani.save("logo.mp4", writer=FFMpegWriter(fps=24))
93+
ani.save("movie.mp4", writer=FFMpegWriter(fps=24))

0 commit comments

Comments
 (0)