{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "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.width = 600\n", "scene.height = 600\n", "show = 'box'\n", "last_show = show\n", " \n", "D = 0.7 # size of box\n", "R = .4 # radius of sphere\n", "\n", "names = ['flower', 'granite', 'gravel', 'metal', 'rock', 'rough', 'rug', 'stones', 'stucco', 'wood', 'wood_old', 'earth']\n", "Ts = [textures.flower, textures.granite, textures.gravel, textures.metal, textures.rock, textures.rough,\n", " textures.rug, textures.stones, textures.stucco, textures.wood, textures.wood_old, textures.earth]\n", "bumps = [ None, None, 'gravel', None, 'rock', None, None, 'stones', 'stucco', None, 'wood_old']\n", "\n", "def erase():\n", " for obj in scene.objects:\n", " obj.visible = False\n", "\n", "def show_object(index, x, y):\n", " T = Ts[index]\n", " B = None\n", " # Bump maps aren't very salient unless one moves the light or rotates the object,\n", " # so don't bother with bump maps unless there's an option to move the light or object.\n", " #if (bumps[index] !== None) B = bumpmaps[bumps[index]]\n", " if show == 'box':\n", " c = box(pos=vec(x,y,0), size=D*vec(1,1,1))\n", " elif show == 'sphere':\n", " c = sphere(pos=vec(x,y,0), size=D*vec(1,1,1))\n", " elif show == 'cylinder': \n", " c = cylinder(pos=vec(x-D/2,y,0), size=D*vec(1,1,1))\n", " elif show == 'cone': \n", " c = cone(pos=vec(x-D/2,y,0), size=D*vec(1,1,1))\n", " elif show == 'pyramid': \n", " c = pyramid(pos=vec(x-D/2,y,0), size=D*vec(1,1,1))\n", " c.index = index\n", " c.shininess = 0\n", " c.texture = {'file':T, 'bumpmap':B}\n", " label(pos=vec(x,y-.5,0), box=0, text='textures.'+names[index])\n", "\n", "def setup():\n", " scene.range = 2.2\n", " scene.fov = 0.2\n", " scene.center = vec(1.5,2,0)\n", " scene.forward = vec(0,0,-1)\n", " erase()\n", " scene.visible = False\n", " index = 0\n", " y = 3.3\n", " while y > 0:\n", " for x in range(4):\n", " if index >= len(names): break; \n", " show_object(index, x, y)\n", " index += 1\n", " y -= 1.3\n", " scene.visible = True\n", "\n", "setup()\n", "scene.visible = False\n", "scene.caption = \"Loading textures...\"\n", "scene.waitfor(\"textures\")\n", "scene.caption = \"Choose the type of object: \"\n", "scene.visible = True\n", "\n", "def choose(c):\n", " global show\n", " show = c.selected\n", " \n", "menu(choices=['box', 'sphere', 'cylinder', 'cone', 'pyramid'], selected='box', bind=choose)\n", "\n", "scene.append_to_caption('\\n\\nClick an object to enlarge it; then click anywhere to show all objects again.')\n", "\n", "hit = None\n", "clicked = False\n", "def handle_click(ev):\n", " global hit, clicked\n", " hit = scene.mouse.pick\n", " clicked = True\n", "scene.bind('click', handle_click)\n", "\n", "def single_object(index):\n", " scene.center = vec(0,-.1*R,0)\n", " scene.range = 1.5*R\n", " erase()\n", " show_object(index, 0, 0)\n", "\n", "picked = None\n", " \n", "while True:\n", " rate(30)\n", " if show != last_show:\n", " last_show = show\n", " if picked != None:\n", " single_object(picked.index)\n", " else:\n", " setup()\n", " if clicked:\n", " clicked = False\n", " if picked != None:\n", " picked = None\n", " setup()\n", " elif picked == None and hit != None:\n", " picked = hit\n", " hit = None\n", " single_object(picked.index)" ] }, { "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.6.0" } }, "nbformat": 4, "nbformat_minor": 1 }