{ "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", "scene.background = color.gray(0.8)\n", "scene.forward = vec(0,-0.2,-1)\n", "scene.fov = 0.2\n", "scene.range = 3.8\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", "\n", "E1 = extrusion(path=[vec(0,0,0), vec(0,0,-0.7)], texture=textures.wood_old,\n", " shape=[ shapes.circle(radius=1.5),\n", " shapes.triangle(pos=[0,-0.6], length=1.2),\n", " shapes.trapezoid(pos=[0,0.6], width=1.6,\n", " height=1, top=0.6) ], pos=vec(-4,1.5,0))\n", "\n", "copper = vec(0.722,0.451,0.200)\n", "E2 = extrusion(path=paths.arc(radius=1.7, angle2=pi), texture=textures.metal, \n", " shape=[ [shapes.triangle(length=2), shapes.circle(pos=[0,.5], radius=0.2),\n", " shapes.trapezoid(pos=[0,-0.2],\n", " width=0.6, height=0.4)],\n", " [shapes.rectangle(pos=[0,1.8],\n", " width=1,height=0.3)] ],\n", " start_face_color=copper, end_face_color=copper)\n", "E2center = E2.pos # initial pos of center of extrusion\n", "E2.pos = vec(3,2,0) # new pos of center of extrsion\n", "E2rot = E2.pos+vec(0,0,-E2center.z) # a location at the front of the extrusion\n", "\n", "halo = ring(pos=vec(0,0,1), radius=0.8, thickness=0.2, color=color.cyan )\n", "\n", "rect = extrusion(path=paths.rectangle(width=5, height=2), \n", " shape=shapes.hexagon(length=0.3), color=color.red)\n", "\n", "bottom = extrusion(path=paths.cross(width=4, thickness=1),\n", " shape=shapes.circle(radius=0.2), color=color.green)\n", "\n", "tube = extrusion(path=[vec(0,0,0), vec(2,0,0)], shape=shapes.circle(radius=0.6, thickness=0.2),\n", " pos=vec(-1,1.7,0), axis=vec(0,0,2), color=color.yellow, end_face_color=color.blue)\n", "text(pos=tube.pos+vec(0,0,1), text='tube', align='center',\n", " height=0.25, depth=0, color=color.blue)\n", "\n", "run = True\n", "\n", "def runner(r):\n", " global run\n", " run = r.checked\n", " \n", "checkbox(bind=runner, text='Run', checked=True)\n", "\n", "#scene.waitfor('textures')\n", "\n", "t = 0\n", "dt = 0.01\n", "dtheta = 0.01\n", "while True:\n", " rate(100)\n", " if run:\n", " halo.pos.x = -1+sin(2*t)\n", " bottom.pos.y = -2+0.5*cos(3*t)\n", " E1.rotate(angle=dtheta, axis=vec(0,1,0))\n", " E2.rotate(angle=-dtheta, axis=vec(0,1,0), origin=E2rot)\n", " t += dt\n", "\n" ] }, { "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 }