{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "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" }, { "data": { "application/javascript": [ "require.undef(\"nbextensions/vpython_libraries/glow.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.undef(\"nbextensions/vpython_libraries/jquery-ui.custom.min\");" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "require([\"nbextensions/vpython_libraries/glow.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": { "application/javascript": [ "require([\"nbextensions/vpython_libraries/jquery-ui.custom.min\"], function(){console.log(\"JQUERY LOADED\");})" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from vpython import *\n", "scene = canvas() # This is needed in Jupyter notebook and lab to make programs easily rerunnable\n", "scene.width = scene.height = 600\n", "scene.background = color.white\n", "scene.range = 1.3\n", "N = 15000\n", "scene.title = 'A {}-element points object with random radii and colors'.format(N)\n", "\n", "run = False\n", "def Runbutton(b):\n", " global run\n", " if b.text == 'Pause':\n", " run = False\n", " b.text = 'Run'\n", " else:\n", " run = True\n", " b.text = 'Pause'\n", "\n", "button(text='Run', bind=Runbutton)\n", "scene.append_to_caption(\"\"\"
Right button drag or Ctrl-drag to rotate \"camera\" to view scene.\n", "Middle button or Alt-drag to drag up or down to zoom in or out.\n", " On a two-button mouse, middle is left + right.\n", "Touch screen: pinch/extend to zoom, swipe or two-finger rotate.\"\"\")\n", "\n", "p = []\n", "last = vec(0,0,0)\n", "for i in range(N):\n", " next = last+0.1*vec.random()\n", " while mag(next) > 1: # if next is outside the sphere, try another random value\n", " next = last+0.1*vec.random()\n", " p.append({'pos':next, 'radius':0.002+0.04*random(), 'color':(vec(1,1,1)+vec.random())/2})\n", " last = next\n", "c = points(pos=p, size_units='world')\n", "while True:\n", " rate(60)\n", " if run: # Currently there isn't a way to rotate a points object, so rotate scene.forward:\n", " scene.forward = scene.forward.rotate(angle=-0.005, axis=vec(0,1,0))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }