{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "298d16e5", "metadata": {}, "outputs": [], "source": [ "# Draw a repeatedly expanding/contracting circle\n", "# pip3 install drawsvg\n", "import drawSvg as draw\n", "\n", "# Draw a frame of the animation\n", "def draw_frame(r):\n", " d = draw.Drawing(250, 250, origin='center')\n", " d.append(draw.Circle(0, 0, r, fill='blue'))\n", " return d\n", " \n", "# run animation\n", "c = 0 # loop counter\n", "r = 0 # starting radius\n", "R = 100 # ending radius\n", "sign = 1 # expansion (1) or contraction (-1)\n", "\n", "with draw.animate_jupyter(draw_frame, delay=0.01) as anim:\n", " while c < 4:\n", " anim.draw_frame(r)\n", " if sign == 1:\n", " r = r + 1 # expand\n", " else:\n", " r = r - 1 # contract\n", " \n", " if r > R or r < 0:\n", " sign = -1 * sign # flip sign of expansion/contraction\n", " c = c + 1 # loop counter" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.6" } }, "nbformat": 4, "nbformat_minor": 5 }