{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/javascript": [ "require.undef(\"nbextensions/vpython_libraries/jquery-ui.custom.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/vpython_libraries/glow.2.1.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/vpython_libraries/glowcomm\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/vpython_libraries/jquery-ui.custom.min\"], function(){console.log(\"JQUERY LOADED\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/vpython_libraries/glow.2.1.min\"], function(){console.log(\"GLOW LOADED\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/vpython_libraries/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 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", "side = 4.0\n", "thk = 0.3\n", "s2 = 2*side - thk\n", "s3 = 2*side + thk\n", "wallR = box (pos=vector( side, 0, 0), size=vector(thk, s2, s3), color = color.red)\n", "wallL = box (pos=vector(-side, 0, 0), size=vector(thk, s2, s3), color = color.red)\n", "wallB = box (pos=vector(0, -side, 0), size=vector(s3, thk, s3), color = color.blue)\n", "wallT = box (pos=vector(0, side, 0), size=vector(s3, thk, s3), color = color.blue)\n", "wallBK = box(pos=vector(0, 0, -side), size=vector(s2, s2, thk), color = color.gray(0.7))\n", "\n", "ball = sphere (color = color.green, radius = 0.4, make_trail=True, retain=100, \n", " trail_color=color.cyan)\n", "ball.mass = 1.0\n", "ball.p = vector(-0.15, -0.23, +0.27)\n", "side = side - thk*0.5 - ball.radius\n", "\n", "dt = 0.5\n", "t = 0.0\n", "while True:\n", " rate(100)\n", " t = t + dt\n", " ball.pos = ball.pos + (ball.p/ball.mass)*dt\n", " if not (side > ball.pos.x > -side):\n", " ball.p.x = -ball.p.x\n", " if not (side > ball.pos.y > -side):\n", " ball.p.y = -ball.p.y\n", " if not (side > ball.pos.z > -side):\n", " ball.p.z = -ball.p.z\n", " " ] }, { "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 }