Skip to content

Commit

Permalink
Merge pull request #5 from trinketapp/v3.1.1
Browse files Browse the repository at this point in the history
V3.1.1
  • Loading branch information
brianpmarks authored Sep 22, 2022
2 parents 5fb113c + 1d21c3b commit 1083775
Show file tree
Hide file tree
Showing 40 changed files with 494 additions and 360 deletions.
2 changes: 1 addition & 1 deletion ForInstalledPython/glow.min.js

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions GlowScriptOffline/VPythonDocs/mouse.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,21 @@ <h1 class="Heading-1"> <font color="#0000A0">Mouse Interactions</font> </
<p class="Normal"><strong><font color="#0000A0">Unbinding</font></strong></p>
<p class="Normal">Suppose you executed <strong>scene.bind('mousedown mousemove', Drag)</strong>, but now you no longer want to send mousemove events to that function. Do this:</p>
<p class="program">scene.unbind('mousemove', Drag)</p>
<p class="Normal">You can also leave a function bound but start and stop having events sent to it:</p>
<p class="program">D = scene.bind('mousemove', Drag)<br />
...<br />
D.stop() # temporarily stop events going to Drag<br />
...<br />
D.start() # start sending events to Drag again
</p>
<p class="Normal">You can check whether the callback is in start or stop mode with <strong>D.enabled</strong>, which is True if the callback has been started and False if it has been stopped.</p>
<p class="Normal">&nbsp;</p>
<p class="Normal"><strong><font color="#0000A0">Custom events: triggers</font></strong> -- <strong class="attribute"><em>THIS CURRENTLY DOES NOT WORK IN VPython</em></strong></p>
<p class="Normal">It is possible to create your own event type, and trigger a callback function to do something. Consider the following example, where the event type is 'color_the_ball':</p>
<p class="Normal"><strong><font color="#0000A0">Custom events: triggers</font></strong></p>
<p class="Normal">It is possible to create your own event type, and trigger a function to do something. Consider the following example, where the custom event type is 'color_the_ball':</p>
<p class="program">def clickFunc():<br />
&nbsp;&nbsp;&nbsp;&nbsp;s = sphere(pos=scene.mouse.pos, radius=0.1)<br />
&nbsp;&nbsp;&nbsp;&nbsp;scene.trigger('color_the_ball', s)<br />
<br />
def ballFunc(newball):<br />
&nbsp;&nbsp;&nbsp;&nbsp;newball.color=color.cyan<br />
def ballFunc(ev): <br>
&nbsp;&nbsp;&nbsp;&nbsp;# ev.type is &quot;color_the_ball&quot;; ev.event is the new sphere<br />
&nbsp;&nbsp;&nbsp;&nbsp;ev.event.color=color.cyan<br />
<br />
scene.bind('click', clickFunc)<br />
scene.bind('color_the_ball', ballFunc)<br />
<br />
box(pos=vector(1,0,0))</p>
<p class="Normal">We bind click events to the function clickFunc, and we bind our own special event type 'color_the_ball' to the function ballFunc. The function clickFunc is executed when the user clicks the mouse. This function creates a small sphere at the location of the mouse click, then triggers an event 'color_the_ball', with the effect of passing to the function ballFunc the sphere object. Finally ballFunc applies a color to the sphere. (Obviously one could color the sphere in clickFunc; the example is just for illustration of the basic concept.) </p>
<p class="Normal">We bind click events to the function clickFunc, and we bind our own special event type 'color_the_ball' to the function ballFunc. The function clickFunc is executed when the user clicks the mouse. This function creates a small sphere at the location of the mouse click, then triggers an event 'color_the_ball', with the effect of passing to the function ballFunc information that includes the new sphere object. Finally ballFunc applies a color to the sphere. (Obviously one could color the sphere in clickFunc; the example is just for illustration of the basic concept.) </p>
<!-- InstanceEndEditable -->
</div>
</div>
Expand Down
46 changes: 24 additions & 22 deletions GlowScriptOffline/VPythonDocs/mouse_drag.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ <h1 class="Heading-1"><font color="#0000A0">Drag Example</font></h1>
s = None # declare s to be used below<br />
<br />
def down():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;s = sphere(pos=scene.mouse.pos,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.red,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size=0.2*vec(1,1,1))<br />
&nbsp;&nbsp;&nbsp;&nbsp;drag = True<br />
<br />
def move():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s <br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s <br />
&nbsp;&nbsp;&nbsp;&nbsp;if drag: # mouse button is down<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pos = scene.mouse.pos<br />
<br />
def up():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;s.color = color.cyan<br />
&nbsp;&nbsp;&nbsp;&nbsp;drag = False<br />
<br />
Expand All @@ -64,29 +64,29 @@ <h1 class="Heading-1"><font color="#0000A0">Drag Example</font></h1>
scene.bind(&quot;mousemove&quot;, move)<br />
<br />
scene.bind(&quot;mouseup&quot;, up)</p>
<p class="Normal">It is also possible to use &quot;anonymous&quot; (unnamed) functions, an extended feature of the RapydScript Python-to-JavaScript compiler, as shown here:</p>
<p class="Normal">It is also possible to use &quot;anonymous&quot; (unnamed) functions, an extended feature of the RapydScript-NG Python-to-JavaScript compiler, as shown here (this will NOT work with installed Python):</p>
<p class="program">scene.range = 5<br />
box()<br />
<br />
drag = False<br />
s = None # declare s to be used below<br />
<br />
scene.bind(&quot;mousedown&quot;, def ():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;s = sphere(pos=scene.mouse.pos,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.red,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size=0.2*vec(1,1,1))<br />
&nbsp;&nbsp;&nbsp;&nbsp;drag = True<br />
)<br />
<br />
scene.bind(&quot;mousemove&quot;, def ():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s <br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s <br />
&nbsp;&nbsp;&nbsp;&nbsp;if drag: # mouse button is down<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.pos = scene.mouse.pos<br />
)<br />
<br />
scene.bind(&quot;mouseup&quot;, def ():<br />
&nbsp;&nbsp;&nbsp;&nbsp;nonlocal drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;global drag, s<br />
&nbsp;&nbsp;&nbsp;&nbsp;s.color = color.cyan<br />
&nbsp;&nbsp;&nbsp;&nbsp;drag = False<br />
)</p>
Expand All @@ -98,21 +98,23 @@ <h1 class="Heading-1"><font color="#0000A0">Drag Example</font></h1>
)</p>
<p class="Normal"><strong>Unbinding:</strong> After binding a function to a mouse event, you can unbind the function, in which case GlowScript will no longer send events to your function. In the program shown above, if you place <span class="attribute">scene.unbind(&quot;mousedown&quot;)</span> in the <span class="attribute">mouseup</span> event, you will be able to drag just one sphere.</p>
<p class="Normal"><strong>Just one:</strong> If you use <span class="attribute">scene.one</span> instead of <span class="attribute">scene.bind</span>, the binding occurs for just one event and then is automatically unbound. In the program shown above, if you specify scene.one for the mousedown event, you will be able to drag just one sphere.</p>
<p class="Normal"><strong>Custom events:</strong> You can set up your own custom events using <span class="attribute">scene.trigger</span>. In the following sample program, first you see a box, then the while loop halts waiting for the custom &quot;ball&quot; event to occur. When you click, the &quot;click&quot; function is executed, and in the click function a sphere is created and a new type of event, &quot;ball&quot;, is triggered by <span class="attribute">scene.trigger</span>, with optional argument <span class="attribute">newball = s</span>. With this triggering of a &quot;ball&quot; event, the &quot;ball&quot; function receives the triggered arguments in <span class="attribute">ev</span> and sets the sphere's color to blue. The triggering of the &quot;ball&quot; function also breaks through the <span class="attribute">scene.waitfor</span> in the while loop that was waiting for a &quot;ball&quot; event. The <span class="attribute">scene.waitfor</span> statement returns the entity that was sent to the &quot;ball&quot; function, and uses the sphere's position to reposition the box. The process in the loop then repeats.</p>
<p class="program">scene.bind(&quot;click&quot;, def ():<br />
&nbsp;&nbsp;&nbsp;&nbsp;s = sphere(pos=scene.mouse.pos)<br />
&nbsp;&nbsp;&nbsp;&nbsp;scene.trigger(&quot;ball&quot;, newball=s)<br />
)<br />
<br />
scene.bind(&quot;ball&quot;, def (ev):<br />
&nbsp;&nbsp;&nbsp;&nbsp;ev.newball.color = color.blue<br />
)<br />
<br />
b = box()<br />
<br />
while True:<br />
&nbsp;&nbsp;&nbsp;&nbsp;ss = scene.waitfor(&quot;ball&quot;)<br />
&nbsp;&nbsp;&nbsp;&nbsp;b.pos = ss.newball.pos + vec(0,-1, 0)</p>
<p class="Normal"><strong>Custom events:</strong> You can set up your own custom events using <span class="attribute">scene.trigger</span>. In the following sample program, first you see a box, then the while loop halts waiting for the custom &quot;ball&quot; event to occur. When you click, the function t is executed, and in this function a sphere is created and a new type of event, &quot;ball&quot;, is triggered by <span class="attribute">scene.trigger</span>, with the optional argument b, representing the new sphere. With this triggering of a &quot;ball&quot; event, function f receives the triggered arguments in <span class="attribute">ev</span> and sets the sphere's color to blue. The triggering of a &quot;ball&quot; event also breaks through the <span class="attribute">scene.waitfor</span> in the while loop that was waiting for a &quot;ball&quot; event. The process in the loop then repeats.</p>
<p class="program">def t():<br>
&nbsp;&nbsp;&nbsp;&nbsp;b = sphere(pos=scene.mouse.pos, radius=0.2)<br>
&nbsp;&nbsp;&nbsp;&nbsp;scene.trigger(&quot;ball&quot;, b)<br>
scene.bind(&quot;click&quot;, t)<br>
<br>
def f(ev): <br>
&nbsp;&nbsp;&nbsp;&nbsp;# ev.type is &quot;ball&quot;; ev.event is newball<br>
&nbsp;&nbsp;&nbsp;&nbsp;ev.event.color = color.blue<br>
scene.bind(&quot;ball&quot;, f)<br>
<br>
cube = box(pos=vec(-2,0,0))<br>
while True:<br>
&nbsp;&nbsp;&nbsp;&nbsp;s = scene.waitfor(&quot;ball&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;print(s.type, s.event.pos) # &quot;ball&quot; and the new sphere's pos<br>
&nbsp;&nbsp;&nbsp;&nbsp;cube.rotate(angle=0.1, axis=vec(0,0,1))</p>
<p class="program">&nbsp;</p>
<p class="program">&nbsp;</p>
<!-- InstanceEndEditable -->
</div>
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GlowScriptOffline/glowscript_libraries/compiler.3.1.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion GlowScriptOffline/glowscript_libraries/glow.3.1.min.js

Large diffs are not rendered by default.

Binary file modified GlowScriptOffline3.1.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run Locally
------------------
At glowscript.org, your programs are stored in the cloud and are accessible from anywhere. However, there are times when you might need to write and run programs even when disconnected from the internet.

In this repository, click GlowScriptOffline2.9.zip and download the zip file.
In this repository, click GlowScriptOffline3.1.zip and download the zip file.

Unzip the GlowScriptOffline package to any convenient place on your computer.

Expand Down
2 changes: 1 addition & 1 deletion build-tools/Symbols.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GlowScript 3.0
GlowScript 3.1
var ver = glowscript.version

console.log( glowscript.glowscript )
Expand Down
21 changes: 15 additions & 6 deletions docs/MakingNewVersion.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,15 @@ for example, GlowScript version 2.2 uses the same verdir value as 2.1 for jquery
In untrusted/run.js, update choice of jquery library.
Add to css/redmond a folder with the new name if necessary (sometimes no change is needed)

Modify build_original.py and property.js to have version = "0.4" and
Modify build_original.py and lib/glow/property.js to have version = "0.4" and
run it to create the final packages for 0.4.
Then change build_original.py and property.js to have version = "0.5dev" and save build_original.py,
Then change build_original.py and lib/glow/property.js to have version = "0.5dev" and save build_original.py,
so that the 0.4 package doesn't get overwritten by accident.

If you're just fixing a bug in 0.4, all you need to do is Deploy from the Google App Engine Launcher,
to update the package files produced in the previous step that involved build.py and property.js.

There is a Glowscript program in build-tools/Symbols.js which you need to copy into (presumably local)
glowscript and run to compile the symbols.
You have to copy and paste the results into the appropriate file (package/symbols.X.Y.min.js).
You also have to make a change at the end of ide/index.html to point to the new Symbols file,
You also have to make a change at the end of ide/templates/index.html to point to the new Symbols file,
since the IDE doesn't yet dynamically load symbols based on the version header.

Also change "G l o w S c r i p t X.Y" appropriately in ide/index.html.
Expand All @@ -78,6 +75,18 @@ Ideally we should create a branch "version-0.4" in the repository at this point,
in case we have to come back and patch an old version for some critical bug.
This has not actually been done so far.

If you're just fixing a bug in 0.4, all you need to do to update the package files produced
in the previous step that involved build.py and property.js is this:

In a terminal, cd to glowscript folder.
Execute 'gcloud info' to check that the project is set to 'glowscript'.
gcloud app deploy --no-promote
This will give a URL to use to test in the cloud, similar to this: https://20211014t164505-dot-glowscript.appspot.com
Alternatively, 'gcloud app browse' brings up glowscript.appspot.com, though I saw this fail (didn't see changes, but this might have been due to caching of an earlier version).
If okay, go to https://console.cloud.google.com/appengine/versions?project=glowscript
You will be in App Engine > Versions; make the window wide to see MIGRATE TRAFFIC.
Choose the new version and then click MIGRATE TRAFFIC to update user glowscript.org

************************************************************************************
UPDATE library files in the GlowScriptOffline package and create zip file
UPDATE the glow library used in VPython 7; generate it with build_original_no_overload.py
Expand Down
4 changes: 2 additions & 2 deletions docs/VPythonDocs/canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More VPython
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.color = color.red </p>
<p class="attributes"> <span class="attribute">visible </span>Setting scene.visible = False means that no objects are displayed, until scene.visible is set True again.</p>
<p class="attributes"><span class="attribute">delete() </span>Deletes all the objects in this canvas and then deletes the canvas itself</p>
<p class="attributes"><span class="attribute">capture(filename) </span>Sends to your Download folder a png screen shot of the canvas. If filename is the string &quot;boxes&quot; or &quot;boxes.png&quot; the file will be named &quot;boxes.png&quot;. If you execute scene.capture(&quot;boxes&quot;) repeatedly, the additional files will be named &quot;boxes(1).png&quot;, &quot;boxes(2).png&quot;, etc. Because label objects are displayed in a separate 2D transparent canvas in front of the 3D canvas, labels are not displayed in a captured scene. If you need text to be part of the captured scene, use the 3D text() object.</p>
<p class="attributes"><span class="attribute">capture(filename) </span>Sends to your Download folder a png screen shot of the canvas. If filename is the string &quot;boxes&quot; or &quot;boxes.png&quot; the file will be named &quot;boxes.png&quot;. If you execute scene.capture(&quot;boxes&quot;) repeatedly, the additional files will be named &quot;boxes(1).png&quot;, &quot;boxes(2).png&quot;, etc. If you do not want to capture "label" objects, execute scene.capture(filename, False)</p>
<p class="attributes"><span class="attribute"><font color="#000000">To obtain the current location of the camera, <a href="#camera"><strong>see </strong></a></font></span><strong><a href="#camera">below</a></strong> for details of <span class="attribute">scene.camera.pos</span><font color="#000000">.</font></p>
<p class="attributes"><span class="attribute">camera.follow</span> If you say <span class="attribute">scene.camera.follow(ball)</span>, the center of the scene will continually be reset to the current position of the ball object. To stop following the object, execute <span class="attribute">scene.camera.follow(None)</span>.</p>
<p class="attributes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Instead of specifying an object to follow, you can provide a function of your own:</p>
Expand Down Expand Up @@ -200,7 +200,7 @@ <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More VPython
<p class="Normal"><strong><font color="#0000A0">Controlling the view using scene.camera</font></strong></p>
<p class="Normal">The mechanisms described above for controlling the view are designed to try to make sure that the objects are visible no matter how the user rotates or zooms the view, because the camera direction is always automatically adjusted to point toward scene.center, which by default is at the origin, and scene.range is automatically adjusted to correspond to the user zoom.</p>
<p class="Normal">However, if you want to &quot;fly&quot; through the scene, with scene.center necessarily varying but zoom held constant, it is more convenient to move and point the camera directly. <span class="attribute"><strong><em>WARNING: </em></strong></span>When you take direct control of the camera, there is increased risk of seeing nothing, due to unintentionally pointing the camera away from the objects, or moving the camera far away from the objects. </p>
<p class="Normal">An example of controlling the camera directly is the fly-through in the program <strong><a href="https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Stonehenge-VPython" target="_blank">Stonehenge</a></strong>, in which changing <span class="attribute">scene.camera.pos</span> (the location of the camera) and <span class="attributes">&nbsp;<span class="attribute">scene.camera.axis</span></span> (the direction the camera is pointing) is a convenient way to move through the scene.</p>
<p class="Normal">An example of controlling the camera directly is the fly-through in the program <strong><a href="https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/Stonehenge-VPython" target="_blank">Stonehenge</a></strong>, in which changing <span class="attribute">scene.camera.pos</span> (the location of the camera) and <span class="attributes">&nbsp;<span class="attribute">scene.camera.axis</span></span> (the direction the camera is pointing) is a convenient way to move through the scene. Using these statements means that you are controlling the view, so autoscaling is turned off (scene.autoscale is set to False).</p>
<p align="center" class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/camera2.png" width="650" height="240" alt="canvas" /></p>
<p class="attributes">&nbsp; </p>
<p class="attributes">&nbsp;<span class="attribute">scene.camera.pos</span><span class="Normal"> The current
Expand Down
Loading

0 comments on commit 1083775

Please sign in to comment.