You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pi # 3.14159.... <br/>
53
-
</p>
53
+
ceil(x) # round up to nearest integer<br/>
54
+
floor(x) # round down to nearest integer<br/>
55
+
round(x) # 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() # random number between 0 and 1</p>
54
59
<pclass="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 "Math" prefix:</p>
55
60
<pclass="program"> Math.ceil(x) # integer closest to x, <=x<br/>
radians, where there are 2*pi radians in 360 degrees: </p>
65
70
<pclass="program">radians(360) # equal to 2*pi<br/>
66
71
degrees(2*pi) # equal to 360</p>
67
-
<pclass="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
-
<pclass="program">t1 = Date().getTime()<br/>
72
+
<pclass="Normal">See JavaScript documentation on the <strong><ahref="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
+
<pclass="Normal">Here is a way to determine elapsed time in milliseconds, with microsecond accuracy. The displayed text is approximately 1500.</p>
74
+
<pclass="program">t1 = performance.now()<br/>
69
75
sleep(1.5,wait)<br/>
70
-
t2 = new Date().getTime()<br/>
76
+
t2 = performance.now()<br/>
71
77
print(t2-t1)</p>
72
78
<pclass="Normal">CoffeeScript:</p>
73
-
<pclass="program">t1 = new Date().getTime()<br/>
79
+
<pclass="program">t1 = performance.now()<br/>
74
80
sleep(1.5,wait)<br/>
75
-
t2 = new Date().getTime()<br/>
81
+
t2 = performance.now()<br/>
76
82
print(t2-t1)</p>
77
83
<pclass="Normal">JavaScript:</p>
78
-
<pclass="program">var t1 = new Date().getTime()<br/>
<pclass="Normal">You can delete the region from the screen with this statement:</p>
76
76
<pclass="program">print_options(delete=True)</p>
77
77
<pclass="Normal">After deleting the region, another print statement will recreate it, with the previously specified width and height. </p>
78
-
<pclass="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
+
<pclass="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>
79
79
<pclass="program">print_options(pos='right')</p>
80
80
<pclass="Normal">You can obtain the current contents of the print region as a character string:</p>
the mouse cursor becomes invisible. This is often appropriate while
95
-
dragging an object using the mouse. Restore the cursor with <spanclass="attribute">scene.cursor.visible
96
-
= True</span>. If <spanclass="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<spanclass="Normal"> named </span><spanclass="attribute">w</span><spanclass="Normal">, use </span><spanclass="attribute">w.cursor.visible = False</span> (this does not currently work on a Macintosh).</p>
97
-
<pclass="attributes"><spanclass="attribute">objects</span> A list
92
+
<pclass="attributes"><spanclass="attribute">objects</span> A list
98
93
of all the visible objects in the display; invisible objects and
99
94
lights are not listed (<spanclass="attribute">scene.lights</span> is a list of existing lights).
100
95
For example, the following makes all visible boxes in the scene red: </p>
101
96
<pclass="program"> for obj in scene2.objects: <br/>
<pclass="attributes"><spanclass="attribute">window</span> There is no wxPython window in GlowScript.</p>
105
-
<pclass="attributes"><spanclass="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
-
<pclass="attributes"><spanclass="attribute">stereo</span> Stereo is currently not supported in GlowScript.</p>
99
+
<pclass="attributes"><spanclass="attribute">cursor.visible</span> Currently not supported in GlowScript.</p>
100
+
<pclass="attributes"><spanclass="attribute">window </span>Currently not supported in GlowScript.</p>
101
+
<pclass="attributes"><spanclass="attribute">delete </span>Currently not supported in GlowScript.</p>
102
+
<pclass="attributes"><spanclass="attribute">stereo</span> Currently not supported in GlowScript.</p>
107
103
<pclass="Normal"><strong><fontcolor="#0000A0">Controlling the display</font></strong></p>
and <spanclass="attribute">title</span> cannot be changed while
110
106
a window is active; they are used to create a display, not to change
111
107
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
-
<pclass="attributes"><spanclass="attribute">x</span>, <spanclass="attribute">y</span> Position of the display on the screen or within a wxPython window (pixels from upper left)</p>
and height of the display area in pixels: scene.height = 200 (includes
115
110
title bar). </p>
116
-
<pclass="attributes"><spanclass="attribute">title</span> Text in the window's
117
-
118
-
title bar: scene.title = 'Planetary Orbit'</p>
111
+
<pclass="attributes"><spanclass="attribute">title</span> Text above the display: scene.title = 'Planetary Orbit'</p>
119
112
<pclass="attributes"><spanclass="attribute">fullscreen</span> Not currently supported in GlowScript.</p>
120
113
<pclass="attributes"><spanclass="attribute">visible</span> Make
121
114
sure the display is visible; <spanclass="attribute">scene2.visible
@@ -166,23 +159,13 @@ <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More VPython
166
159
window as seen by the user. Default pi/3.0 radians (60 degrees).</p>
167
160
<pclass="attributes"><spanclass="attribute">range</span> The extent
168
161
of
169
-
the region of interest to the left or right of <spanclass="attribute">center</span>. This is the inverse of scale, so use either <spanclass="attribute">range</span> or <spanclass="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 <spanclass="attribute">center</span>. Setting range to10 means that scene.center.x+scene.range
173
163
will be at the right edge of a square window. A sphere of radius
174
164
10 will fill the window. A cubical box whose half-width is 10 will
175
165
overfill the window, because the front of the box in 3D appears larger
176
166
than the xy plane passing through scene.center, unless the field
177
167
of view is very small.</p>
178
-
<pclass="attributes"><spanclass="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 <spanclass="attribute">range</span> or <spanclass="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
+
<pclass="attributes"><spanclass="attribute">scale</span> Currently not supported in GlowScript; the inverse of range. </p>
186
169
<pclass="attributes"> <spanclass="attribute">up</span> A vector representing
187
170
188
171
world-space up. This vector will always project to a vertical line on the
<pclass="Normal">The following math functions are provided:</p>
48
+
<pclass="program">abs(x)<br/>
49
+
sqrt(x)<br/>
50
+
sin(x)<br/>
51
+
cos(x)<br/>
52
+
tan(x)<br/>
53
+
asin(x) # arc sine<br/>
54
+
acos(x) # arc cosine<br/>
55
+
atan(x) # arc tangent<br/>
56
+
atan2(y,x) # angle whose tangent is y/x<br/>
57
+
exp(x) # e to the x<br/>
58
+
log(x) # natural log, base e<br/>
59
+
# log(x)/log(10) gives log base 10<br/>
60
+
pow(x,y) # x to the power y<br/>
61
+
pi # 3.14159.... <br/>
62
+
ceil(x) # round up to nearest integer<br/>
63
+
floor(x) # round down to nearest integer<br/>
64
+
round(x) # 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() # random number between 0 and 1</p>
68
+
<pclass="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 "Math" prefix:</p>
69
+
<pclass="program"> Math.ceil(x) # integer closest to x, <=x<br/>
70
+
Math.floor(x) # integer closest to x, >=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
+
<pclass="Normal">There are functions for converting between degrees and
76
+
radians, where there are 2*pi radians in 360 degrees: </p>
77
+
<pclass="program">radians(360) # equal to 2*pi<br/>
78
+
degrees(2*pi) # equal to 360</p>
79
+
<pclass="Normal">See JavaScript documentation on the <strong><ahref="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
+
<pclass="Normal">Here is a way to determine elapsed time in milliseconds, with microsecond accuracy. The displayed text is approximately 1500.</p>
81
+
<pclass="program">t1 = performance.now()<br/>
82
+
sleep(1.5)<br/>
83
+
t2 = performance.now()<br/>
84
+
print(t2-t1)</p>
47
85
</div>
48
86
<div>
49
-
<pclass="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 "floating-point" division.</p>
53
-
<pclass="Normal">In the GlowScript environment, where VPython code is compiled to JavaScript, 3/4 is always 0.75.</p>
0 commit comments