11th grade-all tasks
{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ "import numpy as np\n", "from matplotlib import pyplot as plt\n", "import matplotlib.patches as patches\n", "from matplotlib import animation\n", "from IPython.display import HTML" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "data": { "image/png": "1aaa9f31d416bd14f052e0a727e92b2789bc05ef" }, "metadata": { "image/png": { "height": 143, "width": 713 } } } ], "source": [ "fig = plt.figure()\n", "fig.set_size_inches(12,2)\n", "\n", "d=50\n", "x1, x2 = -10, d\n", "v1 = 5\n", "a = 0\n", "v2 = 9\n", "dt = 0.1\n", "a1 = 0\n", "\n", "ax = plt.axes(xlim=(-10, 200), ylim=(-4, 20))\n", "t1 = plt.text(-x1, 0., \"train1\", size=10,\n", " bbox=dict(boxstyle=\"round\",\n", " ec=(1., 0.5, 0.5),\n", " fc=(1., 0, 0),\n", " )\n", " )\n", "t2 = plt.text(x2, 0., \"train2\", size=10,\n", " bbox=dict(boxstyle=\"round\",\n", " ec=(0., 1, 0.5),\n", " fc=(0.,1, 0),\n", " )\n", " )\n", "plt.plot([0, 200],[0, 0], lw =2 ,c = 'k')\n", "\n", "def init():\n", " \n", " return [t1, t2]\n", "\n", "\n", "def animate(i):\n", " global x1, x2, v1, a\n", " v1 += a * dt\n", " x1 += v1 * dt\n", " x2 += v2 *dt\n", " t1.set_x(x1)\n", " t2.set_x(x2)\n", " return [t1,t2]\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING: Some output was deleted.\n" ] } ], "source": [ "d=50\n", "x1, x2 = -10, d\n", "v1 = 10\n", "a = -0.25\n", "v2 = 5\n", "dt = 0.1\n", "a1 = 0\n", "\n", "\n", "anim = animation.FuncAnimation(fig, animate, \n", " init_func=init, \n", " frames=200, \n", " interval=20,\n", " blit=True)\n", "HTML(anim.to_html5_video())" ] }, { "cell_type": "code", "execution_count": 0, "metadata": { "collapsed": false }, "outputs": [ ], "source": [ ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (Anaconda)", "language": "python", "name": "anaconda3" }, "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.5.4" } }, "nbformat": 4, "nbformat_minor": 0 }