{ "cells": [ { "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([\"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 vpython import *\n", "from numpy import arange, clip\n", "\n", "# David Scherer\n", "\n", "scene.caption = \"\"\"Right button drag or Ctrl-drag to rotate \"camera\" to view scene.\n", "Middle button to drag or Alt-drag to zoom in or out.\n", " On a two-button mouse, middle is left + right.\"\"\"\n", "scene.title = \"Lorenz differential equation\"\n", "scene.center = vector(25,0,0)\n", "scene.background = color.white\n", "scene.forward = vector(0,-.2,-1)\n", "scene.range = 35\n", "\n", "lorenz = curve( color = color.black, radius=0.3 )\n", "\n", "# Draw grid\n", "for x in arange(0,51,10):\n", " box(pos=vector(x,0,0), axis=vector(0,0,50), height=0.4, width=0.4, color=color.gray(0.6) )\n", "for z in arange(-25,26,10):\n", " box(pos=vector(25,0,z), axis=vector(50,0,0), height=0.4, width=0., color=color.gray(0.6) )\n", "\n", "dt = 0.01\n", "y = vector(35, -10, -7)\n", "\n", "for t in arange(0,10,dt):\n", " # Integrate a funny differential equation\n", " dydt = vector( - 8.0/3*y.x + y.y*y.z,\n", " - 10*y.y + 10*y.z,\n", " - y.y*y.x + 28*y.y - y.z );\n", " y = y + dydt*dt\n", "\n", " # Draw lines colored by speed\n", " c = clip( [mag(dydt) * 0.005], 0, 1 )[0]\n", "\n", " lorenz.append( pos=y, color=vector(c,0, 1-c) )\n", "\n", " rate( 500 )" ] }, { "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.5.1" } }, "nbformat": 4, "nbformat_minor": 0 }