Skip to content

Commit 0e82810

Browse files
committed
Much improved rate function; documentation improvements/corrections
1 parent 8645f36 commit 0e82810

13 files changed

+286
-282
lines changed

.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
1015
<triggers>clean,full,incremental,</triggers>
@@ -29,5 +34,6 @@
2934
<nature>org.eclipse.cdt.core.ccnature</nature>
3035
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
3136
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
37+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
3238
</natures>
3339
</projectDescription>

docs/GlowScriptDocs/math.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ <h1 class="Heading-1"> <font color="#0000A0">Math functions</font></h1>
5050
# log(x)/log(10) gives log base 10<br />
5151
pow(x,y) &nbsp;&nbsp;# x to the power y<br />
5252
pi &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# 3.14159.... <br />
53-
</p>
53+
ceil(x)&nbsp;&nbsp;&nbsp;&nbsp;# round up to nearest integer<br />
54+
floor(x)&nbsp;&nbsp;&nbsp;# round down to nearest integer<br />
55+
round(x) &nbsp;&nbsp;# round to nearest integer <br />
56+
max(x,y,z) # the largest of x,y,z<br />
57+
min(x,y,z) # the smallest of x,y,z<br />
58+
random() &nbsp;&nbsp;# random number between 0 and 1</p>
5459
<p class="Normal">The quantities above are simplified forms of the JavaScript functions Math.abs(x), Math.sqrt(x), etc. There are a few other Math functions, which require the &quot;Math&quot; prefix:</p>
5560
<p class="program"> Math.ceil(x) &nbsp;# integer closest to x, &lt;=x<br />
5661
Math.floor(x) # integer closest to x, &gt;=x<br />
@@ -64,20 +69,21 @@ <h1 class="Heading-1"> <font color="#0000A0">Math functions</font></h1>
6469
radians, where there are 2*pi radians in 360 degrees: </p>
6570
<p class="program">radians(360) &nbsp;# equal to 2*pi<br />
6671
degrees(2*pi) # equal to 360</p>
67-
<p class="Normal">See JavaScript documentation on the <strong>Date</strong> object which provides methods for determining the current time. Here is an example for determining elapsed time in milliseconds. The displayed text is approximately 1500.</p>
68-
<p class="program">t1 = Date().getTime()<br />
72+
<p class="Normal">See JavaScript documentation on the <strong><a href="http://www.w3schools.com/jsref/jsref_obj_date.asp" target="_blank">Date</a></strong> object which provides methods for determining the current day etc. </p>
73+
<p class="Normal">Here is a way to determine elapsed time in milliseconds, with microsecond accuracy. The displayed text is approximately 1500.</p>
74+
<p class="program">t1 = performance.now()<br />
6975
sleep(1.5,wait)<br />
70-
t2 = new Date().getTime()<br />
76+
t2 = performance.now()<br />
7177
print(t2-t1)</p>
7278
<p class="Normal">CoffeeScript:</p>
73-
<p class="program">t1 = new Date().getTime()<br />
79+
<p class="program">t1 = performance.now()<br />
7480
sleep(1.5,wait)<br />
75-
t2 = new Date().getTime()<br />
81+
t2 = performance.now()<br />
7682
print(t2-t1)</p>
7783
<p class="Normal">JavaScript:</p>
78-
<p class="program">var t1 = new Date().getTime()<br />
84+
<p class="program">var t1 = performance.now()<br />
7985
sleep(1.5,wait)<br />
80-
var t2 = new Date().getTime()<br />
86+
var t2 = performance.now()<br />
8187
print(t2-t1)</p>
8288
<!-- InstanceEndEditable --></td>
8389
</tr>

docs/GlowScriptDocs/text_output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h1 class="Heading-1"><font color="#0000a0"> Print options</font> </h1>
7575
<p class="Normal">You can delete the region from the screen with this statement:</p>
7676
<p class="program">print_options(delete=True)</p>
7777
<p class="Normal">After deleting the region, another print statement will recreate it, with the previously specified width and height. </p>
78-
<p class="Normal">By default the print area appears underneath the canvas (pos = 'bottom') but you can make it appear to the right of the canvas with this statement:</p>
78+
<p class="Normal">By default the print area appears underneath the canvas (pos = 'bottom') but you can make it appear to the right of the canvas with the following statement (you may have to include something like width=100, because if the window is too narrow to fit the display and the text area side by side, the text area goes below the display):</p>
7979
<p class="program">print_options(pos='right')</p>
8080
<p class="Normal">You can obtain the current contents of the print region as a character string:</p>
8181
<p class="program">text = print_options(contents=True)</p>

docs/VPythonDocs/display.html

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,26 @@ <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More VPython
8989
5. For how to create your own distant and local lights, see <a href="lights.html">Lighting</a>. <br />
9090
</p>
9191
<p class="attributes"><span class="attribute"><font color="#000000">To obtain </font>camera position</span>, see <a href="mouse.html">Mouse Interactions</a>.</p>
92-
<p class="attributes"><span class="attribute">cursor.visible</span> By
93-
setting <span class="attribute">scene.cursor.visible = False</span>,
94-
the mouse cursor becomes invisible. This is often appropriate while
95-
dragging an object using the mouse. Restore the cursor with <span class="attribute">scene.cursor.visible
96-
= True</span>. If <span class="attribute">scene</span> is part of a wxPython window that includes other elements such as buttons, and you want to hide the cursor everywhere in a window<span class="Normal"> named </span><span class="attribute">w</span><span class="Normal">, use </span><span class="attribute">w.cursor.visible = False</span> (this does not currently work on a Macintosh).</p>
97-
<p class="attributes"><span class="attribute">objects</span> A list
92+
<p class="attributes"><span class="attribute">objects</span> A list
9893
of all the visible objects in the display; invisible objects and
9994
lights are not listed (<span class="attribute">scene.lights</span> is a list of existing lights).
10095
For example, the following makes all visible boxes in the scene red: </p>
10196
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;for obj in scene2.objects: <br />
10297
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if isinstance(obj, box):<br />
10398
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.color = color.red</p>
104-
<p class="attributes"><span class="attribute">window</span> There is no wxPython window in GlowScript.</p>
105-
<p class="attributes"><span class="attribute">delete</span> You can delete a display named <strong>d</strong> with <strong>d.delete()</strong> without stopping your program, then create a new display. The delete function deletes all the objects and lights before deleting the display itself. If the display is inside a wxPython window, the window and other widgets in the window remain. You can delete an entire wxPython window named <strong>w</strong> with all its widgets with <strong>w.delete()</strong>. You can delete all windows and displays with <strong>window.delete_all().</strong> Note that it is <strong>window.delete_all()</strong>, not <strong>w.delete_all()</strong>, because the operation affects all windows, not one particular window.</p>
106-
<p class="attributes"><span class="attribute">stereo</span> Stereo is currently not supported in GlowScript.</p>
99+
<p class="attributes"><span class="attribute">cursor.visible</span> Currently not supported in GlowScript.</p>
100+
<p class="attributes"><span class="attribute">window </span>Currently not supported in GlowScript.</p>
101+
<p class="attributes"><span class="attribute">delete </span>Currently not supported in GlowScript.</p>
102+
<p class="attributes"><span class="attribute">stereo</span> Currently not supported in GlowScript.</p>
107103
<p class="Normal"><strong><font color="#0000A0">Controlling the display</font></strong></p>
108-
<p class="Normal">The attributes <span class="attribute">x</span>, <span class="attribute">y</span>, <span class="attribute">width</span>, <span class="attribute">height</span>,
104+
<p class="Normal">The attributes <span class="attribute">width</span>, <span class="attribute">height</span>,
109105
and <span class="attribute">title</span> cannot be changed while
110106
a window is active; they are used to create a display, not to change
111107
one. If these parameters are such as to place part of the display off screen, the width and height are adjusted to fit all of the display onto the screen.</p>
112-
<p class="attributes"> <span class="attribute">x</span>, <span class="attribute">y</span> Position of the display on the screen or within a wxPython window (pixels from upper left)</p>
113-
<p class="attributes"> <span class="attribute">width</span>, <span class="attribute">height</span> Width
108+
<p class="attributes"> <span class="attribute">width</span>, <span class="attribute">height</span> Width
114109
and height of the display area in pixels: scene.height = 200 (includes
115110
title bar). </p>
116-
<p class="attributes"> <span class="attribute">title</span> Text in the window's
117-
118-
title bar: scene.title = 'Planetary Orbit'</p>
111+
<p class="attributes"> <span class="attribute">title</span> Text above the display: scene.title = 'Planetary Orbit'</p>
119112
<p class="attributes"><span class="attribute">fullscreen</span> Not currently supported in GlowScript.</p>
120113
<p class="attributes"> <span class="attribute">visible</span> Make
121114
sure the display is visible; <span class="attribute">scene2.visible
@@ -166,23 +159,13 @@ <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More VPython
166159
window as seen by the user. Default pi/3.0 radians (60 degrees).</p>
167160
<p class="attributes"> <span class="attribute">range</span> The extent
168161
of
169-
the region of interest to the left or right of <span class="attribute">center</span>. This is the inverse of scale, so use either <span class="attribute">range</span> or <span class="attribute">scale</span> depending
170-
on which makes the most
171-
sense in your program. Setting range to 10 is the same as setting
172-
it to (10,10,10). Setting range to (10,10,10) means that scene.center+scene.range
162+
the region of interest to the left or right of <span class="attribute">center</span>. Setting range to10 means that scene.center.x+scene.range
173163
will be at the right edge of a square window. A sphere of radius
174164
10 will fill the window. A cubical box whose half-width is 10 will
175165
overfill the window, because the front of the box in 3D appears larger
176166
than the xy plane passing through scene.center, unless the field
177167
of view is very small.</p>
178-
<p class="attributes"> <span class="attribute">scale</span> A scaling
179-
factor
180-
which scales the region of interest into the sphere with unit radius.
181-
This
182-
is the inverse of range, so use either <span class="attribute">range</span> or <span class="attribute">scale</span> depending
183-
on which makes the most
184-
sense in your program. Setting scale to 0.1 is the same as setting
185-
it to (0.1,0.1,0.1) or setting range to (10,10,10).</p>
168+
<p class="attributes"> <span class="attribute">scale</span> Currently not supported in GlowScript; the inverse of range. </p>
186169
<p class="attributes"> &nbsp;<span class="attribute">up</span> A vector representing
187170

188171
world-space up. This vector will always project to a vertical line on the

docs/VPythonDocs/float.html

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,47 @@
4343
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
4444
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
4545
<div>
46-
<h1 class="Heading-1"> <font color="#0000A0">Floating Division</font></h1>
46+
<h1 class="Heading-1"><font color="#0000A0">Math functions</font></h1>
47+
<p class="Normal">The following math functions are provided:</p>
48+
<p class="program">abs(x)<br />
49+
sqrt(x)<br />
50+
sin(x)<br />
51+
cos(x)<br />
52+
tan(x)<br />
53+
asin(x) &nbsp;&nbsp;&nbsp;# arc sine<br />
54+
acos(x) &nbsp;&nbsp;&nbsp;# arc cosine<br />
55+
atan(x) &nbsp;&nbsp;&nbsp;# arc tangent<br />
56+
atan2(y,x) # angle whose tangent is y/x<br />
57+
exp(x) &nbsp;&nbsp;&nbsp;&nbsp;# e to the x<br />
58+
log(x) &nbsp;&nbsp;&nbsp;&nbsp;# natural log, base e<br />
59+
# log(x)/log(10) gives log base 10<br />
60+
pow(x,y) &nbsp;&nbsp;# x to the power y<br />
61+
pi &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# 3.14159.... <br />
62+
ceil(x)&nbsp;&nbsp;&nbsp;&nbsp;# round up to nearest integer<br />
63+
floor(x)&nbsp;&nbsp;&nbsp;# round down to nearest integer<br />
64+
round(x) &nbsp;&nbsp;# round to nearest integer <br />
65+
max(x,y,z) # the largest of x,y,z<br />
66+
min(x,y,z) # the smallest of x,y,z<br />
67+
random() &nbsp;&nbsp;# random number between 0 and 1</p>
68+
<p class="Normal">The quantities above are simplified forms of the JavaScript functions Math.abs(x), Math.sqrt(x), etc. There are a few other Math functions, which require the &quot;Math&quot; prefix:</p>
69+
<p class="program"> Math.ceil(x) &nbsp;# integer closest to x, &lt;=x<br />
70+
Math.floor(x) # integer closest to x, &gt;=x<br />
71+
Math.round(x) # integer closest to x <br />
72+
Math.max(a,b,c,..) # maximum of these<br />
73+
Math.min(a,b,c,..) # minimum of these<br />
74+
Math.random() # pseudorandom number 0 to 1 </p>
75+
<p class="Normal">There are functions for converting between degrees and
76+
radians, where there are 2*pi radians in 360 degrees: </p>
77+
<p class="program">radians(360) &nbsp;# equal to 2*pi<br />
78+
degrees(2*pi) # equal to 360</p>
79+
<p class="Normal">See JavaScript documentation on the <strong><a href="http://www.w3schools.com/jsref/jsref_obj_date.asp" target="_blank">Date</a></strong> object which provides methods for determining the current day etc. </p>
80+
<p class="Normal">Here is a way to determine elapsed time in milliseconds, with microsecond accuracy. The displayed text is approximately 1500.</p>
81+
<p class="program">t1 = performance.now()<br />
82+
sleep(1.5)<br />
83+
t2 = performance.now()<br />
84+
print(t2-t1)</p>
4785
</div>
4886
<div>
49-
<p class="Normal"> For versions of Python prior to 3.0, Python performs integer division with truncation,
50-
so that 3/4 is 0, not 0.75. This is inconvenient when doing scientific computations,
51-
and can lead to hard-to-find bugs in programs. You can write 3./4., which
52-
is 0.75 by the rules of &quot;floating-point&quot; division.</p>
53-
<p class="Normal">In the GlowScript environment, where VPython code is compiled to JavaScript, 3/4 is always 0.75.</p>
5487
<div> </div>
5588
</div>
5689
<br />

docs/VPythonDocs/math.html

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<!-- InstanceBeginEditable name="doctitle" -->
6+
<title>VPython Help</title>
7+
<!-- InstanceEndEditable -->
8+
<!-- InstanceBeginEditable name="head" -->
9+
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
10+
<!-- InstanceEndEditable -->
11+
<script type="text/javascript">
12+
<!--
13+
function MM_jumpMenu(targ,selObj,restore){ //v3.0
14+
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
15+
if (restore) selObj.selectedIndex=0;
16+
}
17+
//-->
18+
</script>
19+
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
20+
</head>
21+
22+
<body>
23+
<table width="800" border="0" cellpadding="1" cellspacing="0">
24+
<!--DWLayoutDefaultTable-->
25+
<tr>
26+
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
27+
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p>&nbsp;</p> </td>
28+
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
29+
<p class="Normal">If you're new to Python <br />
30+
and VPython: <a href="VisualIntro.html">Introduction</a></p>
31+
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
32+
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
33+
<p><select id="menu1" onchange="jumpMenu(this)"></select></p>
34+
<p><select id="menu2" onchange="jumpMenu(this)"></select></p>
35+
<p><select id="menu3" onchange="jumpMenu(this)"></select></p>
36+
37+
<p class="Normal">What's new in <a href="new_features.html">VPython 6</a></p>
38+
<p class="Normal"><a href="http://vpython.org" target="_blank">VPython web site</a><br />
39+
<a href="license.txt" target="_blank">VPython license</a><br />
40+
<a href="http://www.python.org" target="_blank">Python web site</a> <br />
41+
<a href="http://www.python.org/doc/2.5.2/lib/module-math.html" target="_blank">Math module</a> (sqrt etc.)<br />
42+
<a href="http://www.scipy.org/Documentation" target="_blank">Numpy module</a> (arrays) </p></td>
43+
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
44+
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
45+
<div>
46+
<h1 class="Heading-1"> <font color="#0000A0">Floating Division</font></h1>
47+
</div>
48+
<div>
49+
<p class="Normal"> For versions of Python prior to 3.0, Python performs integer division with truncation,
50+
so that 3/4 is 0, not 0.75. This is inconvenient when doing scientific computations,
51+
and can lead to hard-to-find bugs in programs. You can write 3./4., which
52+
is 0.75 by the rules of &quot;floating-point&quot; division.</p>
53+
<p class="Normal">In the GlowScript environment, where VPython code is compiled to JavaScript, 3/4 is always 0.75.</p>
54+
<div> </div>
55+
</div>
56+
<br />
57+
<!-- InstanceEndEditable --></td>
58+
</tr>
59+
<tr>
60+
<td height="16" colspan="4"></td>
61+
</tr>
62+
</table>
63+
</body>
64+
<script type="text/javascript" language="javascript" src="navigation.js"></script>
65+
<!-- InstanceEnd --></html>

examples/DancingPendulums.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ var link = $("<a/>").prop("href", "http://sciencedemonstrations.fas.harvard.edu/
3232
link.text("Based on this video")
3333
link.appendTo( $("<div/>").appendTo( canvas.container ) )
3434

35-
var start = new Date().getTime()
35+
var start = performance.now()
3636
while (true) {
37-
var t = (new Date().getTime() - start)*.001
37+
var t = (performance.now() - start)*.001
3838
scene.caption.text("t=" + t.toFixed(1))
3939
for(var i=0; i<pendulums.length; i++) {
4040
var p = pendulums[i]

0 commit comments

Comments
 (0)