|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 | 5 | "execution_count": null,
|
6 |
| - "metadata": { |
7 |
| - "collapsed": false |
8 |
| - }, |
| 6 | + "metadata": {}, |
9 | 7 | "outputs": [
|
10 | 8 | {
|
11 | 9 | "data": {
|
|
22 | 20 | {
|
23 | 21 | "data": {
|
24 | 22 | "application/javascript": [
|
25 |
| - "window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")}" |
| 23 | + "if (typeof Jupyter !== \"undefined\") { window.__context = { glowscript_container: $(\"#glowscript\").removeAttr(\"id\")};}else{ element.textContent = ' ';}" |
| 24 | + ], |
| 25 | + "text/plain": [ |
| 26 | + "<IPython.core.display.Javascript object>" |
| 27 | + ] |
| 28 | + }, |
| 29 | + "metadata": {}, |
| 30 | + "output_type": "display_data" |
| 31 | + }, |
| 32 | + { |
| 33 | + "data": { |
| 34 | + "application/javascript": [ |
| 35 | + "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glow.min\");}else{element.textContent = ' ';}" |
| 36 | + ], |
| 37 | + "text/plain": [ |
| 38 | + "<IPython.core.display.Javascript object>" |
| 39 | + ] |
| 40 | + }, |
| 41 | + "metadata": {}, |
| 42 | + "output_type": "display_data" |
| 43 | + }, |
| 44 | + { |
| 45 | + "data": { |
| 46 | + "application/javascript": [ |
| 47 | + "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/glowcomm\");}else{element.textContent = ' ';}" |
| 48 | + ], |
| 49 | + "text/plain": [ |
| 50 | + "<IPython.core.display.Javascript object>" |
| 51 | + ] |
| 52 | + }, |
| 53 | + "metadata": {}, |
| 54 | + "output_type": "display_data" |
| 55 | + }, |
| 56 | + { |
| 57 | + "data": { |
| 58 | + "application/javascript": [ |
| 59 | + "if (typeof Jupyter !== \"undefined\") {require.undef(\"nbextensions/vpython_libraries/jquery-ui.custom.min\");}else{element.textContent = ' ';}" |
| 60 | + ], |
| 61 | + "text/plain": [ |
| 62 | + "<IPython.core.display.Javascript object>" |
| 63 | + ] |
| 64 | + }, |
| 65 | + "metadata": {}, |
| 66 | + "output_type": "display_data" |
| 67 | + }, |
| 68 | + { |
| 69 | + "data": { |
| 70 | + "application/javascript": [ |
| 71 | + "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glow.min\"], function(){console.log(\"GLOW LOADED\");});}else{element.textContent = ' ';}" |
| 72 | + ], |
| 73 | + "text/plain": [ |
| 74 | + "<IPython.core.display.Javascript object>" |
| 75 | + ] |
| 76 | + }, |
| 77 | + "metadata": {}, |
| 78 | + "output_type": "display_data" |
| 79 | + }, |
| 80 | + { |
| 81 | + "data": { |
| 82 | + "application/javascript": [ |
| 83 | + "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/glowcomm\"], function(){console.log(\"GLOWCOMM LOADED\");});}else{element.textContent = ' ';}" |
| 84 | + ], |
| 85 | + "text/plain": [ |
| 86 | + "<IPython.core.display.Javascript object>" |
| 87 | + ] |
| 88 | + }, |
| 89 | + "metadata": {}, |
| 90 | + "output_type": "display_data" |
| 91 | + }, |
| 92 | + { |
| 93 | + "data": { |
| 94 | + "application/javascript": [ |
| 95 | + "if (typeof Jupyter !== \"undefined\") {require([\"nbextensions/vpython_libraries/jquery-ui.custom.min\"], function(){console.log(\"JQUERY LOADED\");});}else{element.textContent = ' ';}" |
26 | 96 | ],
|
27 | 97 | "text/plain": [
|
28 | 98 | "<IPython.core.display.Javascript object>"
|
|
34 | 104 | ],
|
35 | 105 | "source": [
|
36 | 106 | "from vpython import *\n",
|
37 |
| - "scene = canvas() # This is needed in Jupyter notebook and lab to make programs easily rerunnable\n", |
38 |
| - "# This version uses VPython widgets: button, radio button, checkbox, slider, menu\n", |
39 |
| - "# See ButtonsSlidersMenus1 for a version that uses Jupyter notebook widgets: button, slider, menu\n", |
40 | 107 | "scene.width = 350\n",
|
41 | 108 | "scene.height = 300\n",
|
42 | 109 | "scene.range = 1.3\n",
|
|
56 | 123 | "cone_object = cone(visible=False, radius=0.5)\n",
|
57 | 124 | "pyramid_object = pyramid(visible=False)\n",
|
58 | 125 | "cylinder_object = cylinder(visible=False, radius=0.5)\n",
|
59 |
| - "sphere(radius=0.3)\n", |
60 | 126 | "\n",
|
61 | 127 | "col = color.cyan\n",
|
62 | 128 | "currentobject = box_object\n",
|
|
66 | 132 | " global col\n",
|
67 | 133 | " if col.equals(color.cyan): # change to red\n",
|
68 | 134 | " currentobject.color = col = color.red\n",
|
| 135 | + " c.text = \"<b>Cyan</b>\"\n", |
| 136 | + " c.color = color.cyan\n", |
| 137 | + " c.background = color.red\n", |
| 138 | + " if c.name is None: # this is the top button\n", |
| 139 | + " r1.checked = False\n", |
| 140 | + " r2.checked = True\n", |
| 141 | + " else: # change to cyan\n", |
| 142 | + " currentobject.color = col = color.cyan\n", |
| 143 | + " c.text = \"<b>Red</b>\"\n", |
| 144 | + " c.color = color.red\n", |
| 145 | + " c.background = color.cyan\n", |
| 146 | + " if c.name is None: # this is the top button\n", |
| 147 | + " r1.checked = True\n", |
| 148 | + " r2.checked = False\n", |
| 149 | + " \n", |
| 150 | + "def cc(c):\n", |
| 151 | + " global col\n", |
| 152 | + " if col.equals(color.cyan): # change to red:\n", |
| 153 | + " currentobject.color = col = color.red\n", |
69 | 154 | " cbutton.text = \"<b>Cyan</b>\"\n",
|
70 |
| - " cbutton.textcolor = color.cyan\n", |
| 155 | + " cbutton.color = color.cyan\n", |
71 | 156 | " cbutton.background = color.red\n",
|
72 |
| - " r1.checked = False\n", |
73 |
| - " r2.checked = True\n", |
74 | 157 | " else: # change to cyan\n",
|
75 | 158 | " currentobject.color = col = color.cyan\n",
|
76 | 159 | " cbutton.text = \"<b>Red</b>\"\n",
|
77 |
| - " cbutton.textcolor = color.red\n", |
| 160 | + " cbutton.color = color.red\n", |
78 | 161 | " cbutton.background = color.cyan\n",
|
79 |
| - " r1.checked = True\n", |
80 |
| - " r2.checked = False\n", |
81 | 162 | " \n",
|
82 |
| - "cbutton = button(text='<b>Red</b>', textcolor=color.red, background=color.cyan, pos=scene.title_anchor, bind=Color)\n", |
| 163 | + "cbutton = button(text='<b>Red</b>', color=color.red, background=color.cyan, \n", |
| 164 | + " pos=scene.title_anchor, bind=Color, name=None)\n", |
| 165 | + "\n", |
| 166 | + "scene.caption = \"Vary the rotation speed: \\n\\n\"\n", |
83 | 167 | "\n",
|
84 |
| - "scene.caption = \"Vary the rotation speed: \\n\"\n", |
85 |
| - "speed = 150\n", |
86 | 168 | "def setspeed(s):\n",
|
87 |
| - " global speed\n", |
88 |
| - " speed = s.value\n", |
| 169 | + " wt.text = '{:1.2f}'.format(s.value)\n", |
89 | 170 | " \n",
|
90 |
| - "slider(min=20, max=500, value=250, length=350, bind=setspeed)\n", |
| 171 | + "sl = slider(min=0.3, max=3, value=1.5, length=220, bind=setspeed, right=15)\n", |
91 | 172 | "\n",
|
92 |
| - "scene.append_to_caption('\\n')\n", |
| 173 | + "wt = wtext(text='{:1.2f}'.format(sl.value))\n", |
93 | 174 | "\n",
|
94 |
| - "r1 = radio(bind=Color, checked=True, text='Cyan ')\n", |
| 175 | + "scene.append_to_caption(' radians/s\\n')\n", |
| 176 | + "\n", |
| 177 | + "r1 = radio(bind=cc, checked=True, text='Cyan', name='rads')\n", |
95 | 178 | "\n",
|
96 | 179 | "scene.append_to_caption(' ')\n",
|
97 | 180 | "\n",
|
|
118 | 201 | "\n",
|
119 | 202 | "scene.append_to_caption('\\n')\n",
|
120 | 203 | "\n",
|
121 |
| - "r2 = radio(bind=Color, text='Red ')\n", |
| 204 | + "r2 = radio(bind=cc, text='Red', name='rads')\n", |
122 | 205 | "\n",
|
123 | 206 | "scene.append_to_caption(' ')\n",
|
124 | 207 | "\n",
|
|
128 | 211 | " else:\n",
|
129 | 212 | " currentobject.opacity = 1\n",
|
130 | 213 | "\n",
|
131 |
| - "trans = checkbox(bind=transparency, text='Transparent')\n", |
| 214 | + "checkbox(bind=transparency, text='Transparent')\n", |
132 | 215 | "\n",
|
| 216 | + "dt = 0.01\n", |
133 | 217 | "while True:\n",
|
134 |
| - " rate(100)\n", |
| 218 | + " rate(1/dt)\n", |
135 | 219 | " if running:\n",
|
136 |
| - " currentobject.rotate(angle=speed*1e-4, axis=vector(0,1,0))\n" |
| 220 | + " currentobject.rotate(angle=sl.value*dt, axis=vector(0,1,0))\n" |
137 | 221 | ]
|
138 | 222 | },
|
139 | 223 | {
|
140 | 224 | "cell_type": "code",
|
141 | 225 | "execution_count": null,
|
142 | 226 | "metadata": {
|
143 |
| - "collapsed": true |
| 227 | + "collapsed": true, |
| 228 | + "jupyter": { |
| 229 | + "outputs_hidden": true |
| 230 | + } |
144 | 231 | },
|
145 | 232 | "outputs": [],
|
146 | 233 | "source": []
|
|
163 | 250 | "name": "python",
|
164 | 251 | "nbconvert_exporter": "python",
|
165 | 252 | "pygments_lexer": "ipython3",
|
166 |
| - "version": "3.6.6" |
| 253 | + "version": "3.9.7" |
167 | 254 | }
|
168 | 255 | },
|
169 | 256 | "nbformat": 4,
|
170 |
| - "nbformat_minor": 2 |
| 257 | + "nbformat_minor": 4 |
171 | 258 | }
|
0 commit comments