{ "cells": [ { "cell_type": "markdown", "id": "81d76ce2", "metadata": {}, "source": [ "# Flag\n", "\n", "This example uses the `math()` animation to animate the `y1` and `y2` properties of a `fill_between()` plot object." ] }, { "cell_type": "code", "execution_count": null, "id": "9e6d4f88", "metadata": {}, "outputs": [], "source": [ "import diplotocus as dpl\n", "import numpy as np\n", "\n", "tl = dpl.Timeline(xlim=(-0.1,1.6),ylim=(-1,1),noaxis=True,figsize=(7,7))\n", "\n", "x = np.linspace(0,1.5,100)\n", "\n", "f1 = dpl.fill_between(x=x ,y1=0,y2=1,fc='k')\n", "f2 = dpl.fill_between(x=x ,y1=0,y2=1,fc='g')\n", "f3 = dpl.fill_between(x=x/3,y1=0,y2=1,fc='r')\n", "f1.math('y1',lambda t: np.sin((x *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 + .33/2 ,60)\n", "f1.math('y2',lambda t: np.sin((x *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 + .5 ,60)\n", "f2.math('y1',lambda t: np.sin((x *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 - .5 ,60)\n", "f2.math('y2',lambda t: np.sin((x *2*np.pi)**0.5)*np.sin(t*2*np.pi-x/0.5)/3 - .33/2 ,60)\n", "f3.math('y1',lambda t:(np.sin((x/3*2*np.pi)**0.5)*np.sin(t*2*np.pi-x/1.5)/3 - .5*(1-x/1.5)),60)\n", "f3.math('y2',lambda t:(np.sin((x/3*2*np.pi)**0.5)*np.sin(t*2*np.pi-x/1.5)/3 + .5*(1-x/1.5)),60)\n", "\n", "tl.animate((f1,f2,f3))\n", "tl.save_video('../../_static/examples/flag.mp4')" ] }, { "cell_type": "code", "execution_count": 6, "id": "577bd7d9", "metadata": { "tags": [ "remove-input" ] }, "outputs": [ { "data": { "text/html": [ "\n", " \n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from IPython.display import HTML, display\n", "display(HTML(\"\"\"\n", " \n", "\"\"\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.3" } }, "nbformat": 4, "nbformat_minor": 5 }