{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.1\n", "C:\\Anaconda3\\lib\\site-packages\\vpython/data/glow.2.1.min.js\n" ] }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/jquery-ui.custom.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/glow.\"+GSversion[0]+\".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([\"nbextensions/jquery-ui.custom.min\"], function(){console.log(\"jquery loaded\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/glow.\"+GSversion[0]+\".min\"], function(){console.log(\"glow loaded\");})" ], "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" }, { "name": "stdout", "output_type": "stream", "text": [ "C:\\Anaconda3\\lib\\site-packages\\vpython/data/glow.2.1.min\n" ] }, { "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 vpython import *\n", "\n", "scene.caption = \"\"\"Right button drag or Ctrl-drag to rotate \"camera\" to view scene.\n", "To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel.\n", " On a two-button mouse, middle is left + right.\n", "Touch screen: pinch/extend to zoom, swipe or two-finger rotate.\"\"\"\n", "\n", "scene.forward = vector(0,-.3,-1)\n", "\n", "G = 6.7e-11\n", "\n", "giant = sphere(pos=vector(-1e11,0,0), radius=2e10, color=color.red, \n", " make_trail=True, trail_type='points', interval=10, retain=20)\n", "giant.mass = 2e30\n", "giant.p = vector(0, 0, -1e4) * giant.mass\n", "\n", "dwarf = sphere(pos=vector(1.5e11,0,0), radius=1e10, color=color.yellow,\n", " make_trail=True, retain=40)\n", "dwarf.mass = 1e30\n", "dwarf.p = -giant.p\n", "\n", "dt = 1e5\n", "while True:\n", " rate(200)\n", "\n", " r = dwarf.pos - giant.pos\n", " F = G * giant.mass * dwarf.mass * norm(r) / mag2(r)\n", " giant.p = giant.p + F*dt\n", " dwarf.p = dwarf.p - F*dt\n", " giant.pos = giant.pos + (giant.p/giant.mass) * dt\n", " dwarf.pos = dwarf.pos + (dwarf.p/dwarf.mass) * dt" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "VPython", "language": "python", "name": "vpython" }, "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 }