Created
September 21, 2019 14:08
-
-
Save LuxXx/942612d030457e28315ea6bd0243d3b4 to your computer and use it in GitHub Desktop.
How I make my animations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 21, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import numpy as np\n", | |
| "import matplotlib\n", | |
| "matplotlib.use('Agg')\n", | |
| "import matplotlib.pyplot as plt" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 55, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "frames = 240\n", | |
| "f = np.sin\n", | |
| "a = 0\n", | |
| "b = 4 * np.pi\n", | |
| "x = np.linspace(a, b, frames, endpoint=True)\n", | |
| "y = f(x)\n", | |
| "y_max = y.max() + (y.max() - y.min()) / 3\n", | |
| "y_min = y.min() - (y.max() - y.min()) / 3" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 56, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "for k in range(frames):\n", | |
| " plt.figure()\n", | |
| " plt.ylim((y_min, y_max))\n", | |
| " plt.xlim((a, b))\n", | |
| " \n", | |
| " x = np.linspace(a, b, frames, endpoint=True)\n", | |
| " plt.plot(x[:k], f(x)[:k]);\n", | |
| " \n", | |
| " plt.gca().spines['right'].set_visible(False)\n", | |
| " plt.gca().spines['top'].set_visible(False)\n", | |
| " \n", | |
| " plt.savefig('sin/out_' + str(k) + '.png');\n", | |
| " plt.close('all')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 57, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[]" | |
| ] | |
| }, | |
| "execution_count": 57, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "%%system\n", | |
| "ffmpeg -loglevel warning -y -i sin/out_%d.png -c:v libx264 -vf fps=30 -pix_fmt yuv420p sin.mp4" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 58, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<video autoplay loop controls>\n", | |
| " <source src=\"sin.mp4\" type=\"video/mp4\">\n", | |
| "</video>\n" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "%%HTML\n", | |
| "<video autoplay loop controls>\n", | |
| " <source src=\"sin.mp4\" type=\"video/mp4\">\n", | |
| "</video>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "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.7.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment