@@ -134,7 +134,7 @@ def setup(nseconds=15):
134134 return npoints, learner, data, rounded_corners, fig, ax
135135
136136
137- def animate_mp4(fname="source/_static/logo_docs.mp4"):
137+ def animate_mp4(fname="source/_static/logo_docs.mp4", nseconds=15 ):
138138 npoints, learner, data, rounded_corners, fig, ax = setup()
139139 artists = [
140140 get_new_artists(n, learner, data, rounded_corners, ax) for n in tqdm(npoints)
@@ -143,36 +143,40 @@ def animate_mp4(fname="source/_static/logo_docs.mp4"):
143143 ani.save(fname, writer=FFMpegWriter(fps=24))
144144
145145
146- def animate_png(folder="source/_static/logo ", nseconds=2 ):
146+ def animate_png(folder="/tmp ", nseconds=15 ):
147147 npoints, learner, data, rounded_corners, fig, ax = setup(nseconds)
148148 folder = Path(folder)
149149 folder.mkdir(parents=True, exist_ok=True)
150150 fnames = []
151+ ims = []
151152 for n in tqdm(npoints):
152153 fname = folder / f"logo_docs_{n:03d}.png"
153154 fnames.append(fname)
154- npoints, learner, data, _, fig, ax = setup(nseconds=2 )
155+ npoints, learner, data, _, fig, ax = setup(nseconds)
155156 get_new_artists(n, learner, data, None, ax)
156157 fig.savefig(fname, transparent=True)
157158 ax.cla()
158- remove_rounded_corners(fname)
159- return fnames
159+ plt.close(fig)
160+ im = remove_rounded_corners(fname)
161+ ims.append(im)
162+ return fnames, ims
160163
161164
162165if __name__ == "__main__":
163- fname = Path("_static/logo_docs.mp4")
164- # if not fname.exists():
165- # ar = animate_mp4(fname)
166- animate_png()
167- ```
168-
169- ``` {code-cell} ipython3
170- n = 10
171- folder = Path("source/_static/logo")
172- fname = folder / f"logo_docs_{n:03d}.png"
173- npoints, learner, data, rounded_corners, fig, ax = setup(nseconds=2)
174- get_new_artists(n, learner, data, None, ax)
175- fig.savefig(fname, transparent=True)
166+ fname_mp4 = Path("_static/logo_docs.mp4")
167+ if not fname_mp4.exists():
168+ animate_mp4(fname_mp4)
169+ fname_webp = fname_mp4.with_suffix(".webp")
170+ if not fname_webp.exists():
171+ fnames, ims = animate_png()
172+ im.save(
173+ fname_webp,
174+ save_all=True,
175+ append_images=_ims,
176+ opimize=False,
177+ durarion=2,
178+ quality=70,
179+ )
176180```
177181
178182``` {eval-rst}
0 commit comments