{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Orbits, with Vpython used to render the result, and ipywidgets used for interactivity.\n", "The first cell defines the classes used, which could be reused for other demonstrations, and the second cell defines the interactions." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "require.undef(\"nbextensions/jquery-ui.custom.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glow.2.1.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glowcomm\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/pako.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/pako_deflate.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/pako_inflate.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/glowcomm\"], function(){console.log(\"glowcomm loaded\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from pycav.mechanics import *\n", "from vpython import *\n", "import numpy as np\n", "from ipywidgets import widgets" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")}" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "def b_handler(s):\n", " global running\n", " running = True\n", " if running:\n", " dwarf_planet.pos = np.array([x.value,0.,0.])\n", " dwarf_planet.v = np.array([0.,0.,velocity.value])\n", " dwarf_planet.make_trail = False\n", " dwarf_planet.make_trail = True\n", " print(velocity)\n", " while True:\n", " rate(60)\n", " system.simulate(dt)\n", "\n", "\n", "scene1 = canvas(title = \"Orbits\")\n", "scene1.forward = vector(0,1,0)\n", "giant_planet = Particle(pos = np.array([2.,0.,0.]), v = np.array([0., 0., 0.]), inv_mass = 1./200000., radius = 20, fixed = True)\n", "dwarf_planet = Particle(pos = np.array([200.,0.,0.]), v = np.array([0., 0., 31.622]), inv_mass = 1./1., radius = 10)\n", "\n", "dt = 0.01\n", "planets_array = [giant_planet, dwarf_planet]\n", "system = System(collides = False, interacts = True, visualize = True, particles = planets_array, canvas = scene1)\n", "system.planets = planets_array\n", "\n", "running = False\n", "\n", "b = widgets.Button(description='Update')\n", "display(b)\n", "b.on_click(b_handler)\n", "\n", "x = widgets.FloatSlider(description='Radius:', min=100, max=500, step=1, value=200)\n", "display(x)\n", "velocity = widgets.FloatSlider(description='Velocity:', min=20, max=100, step=1, value=31)\n", "display(velocity)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "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.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }