{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "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" }, { "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", "from time import clock\n", "\n", "N = 10\n", "\n", "scene.title = \"{} by {} by {} = {} rotating boxes\".format(N,N,N,N**3)\n", "\n", "boxes = []\n", "\n", "L = 6\n", "scene.range = L\n", "length = 0.6*L/N\n", "height = 0.4*L/N\n", "\n", "for x in range(N):\n", " for y in range(N):\n", " for z in range(N):\n", " b = box(color=vector(x/N,y/N,z/N),\n", " pos=vector(L*(x/(N-1)-.5),L*(y/(N-1)-.5),L*(z/(N-1)-.5)),\n", " size=vector(length,height,length))\n", " boxes.append(b)\n", "\n", "t = 0\n", "dt = 0.01\n", "loops = 0\n", "ctime = 0\n", "start = clock()\n", "N = 200\n", "\n", "# 6.4/100\n", "\n", "while True:\n", " if loops == N:\n", " s = '{:0.1f} millisecond computation per loop'.format(1000*ctime/loops)\n", " s += '\\n{:3.0f} loops per second'.format(loops/(clock()-start))\n", " scene.caption = s\n", " ctime = 0\n", " loops = 0\n", " start = clock()\n", " rate(N)\n", " t += dt\n", " ct = clock()\n", " v = length*vector(sin(t), 0, cos(t))\n", " for b in boxes:\n", " b.axis = v\n", " ctime += clock()-ct\n", " loops += 1" ] }, { "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 }