File: display.html

package info (click to toggle)
python-visual 1%3A5.12-1.6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 7,708 kB
  • ctags: 7,635
  • sloc: cpp: 15,593; sh: 9,615; ansic: 6,631; python: 4,737; makefile: 384
file content (316 lines) | stat: -rw-r--r-- 22,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/visual/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>display</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" /><!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="800" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutDefaultTable-->
  <tr>
    <td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p>&nbsp;</p>    </td>
    <td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
      <p class="Normal">If you're new to Python <br />
      and VPython: <a href="VisualIntro.html">Introduction</a></p>
      <p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
      <p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
      <p class="Normal">Choose a 3D object:</p>
        <select name="jumpMenu4" id="jumpMenu4" onchange="MM_jumpMenu('parent',this,0)">
          <option>Choose an object</option>
          <option value="cylinder.html">Overview</option>
          <option value="arrow.html">arrow</option>
          <option value="box.html">box</option>
          <option value="cone.html">cone</option>
          <option value="convex.html">convex</option>
          <option value="curve.html">curve</option>
          <option value="cylinder.html">cylinder</option>
          <option value="ellipsoid.html">ellipsoid</option>
          <option value="faces.html">faces</option>
          <option value="frame.html">frame</option>
          <option value="helix.html">helix</option>
          <option value="label.html">label</option>
          <option value="lights.html">lights</option>
          <option value="points.html">points</option>
          <option value="pyramid.html">pyramid</option>
          <option value="ring.html">ring</option>
          <option value="sphere.html">sphere</option>
        </select>
        
      <p class="Normal">Work with 3D objects:</p>
        <select name="jumpMenu4" id="jumpMenu5" onchange="MM_jumpMenu('parent',this,0)">
          <option>Choose an option</option>
          <option value="color.html">Color &amp; Opacity</option>
          <option value="lights.html">Lighting</option>
          <option value="materials.html">Materials &amp; Textures</option>
          <option value="defaults.html">Defaults</option>
          <option value="rate.html">Animation Speed</option>
          <option value="rotation.html">Rotations</option>
          <option value="options.html">Additional Options</option>
          <option value="delete.html">Delete an Object</option>
          <option value="float.html">3/4 = 0?</option>
        </select>
        
      <p class="Normal">Windows, Events, &amp; Files:</p>
        <select name="jumpMenu4" id="jumpMenu6" onchange="MM_jumpMenu('parent',this,0)">
          <option>Choose a topic</option>
          <option value="display.html">Windows</option>
          <option value="lights.html">Lighting</option>
          <option value="mouse.html">Mouse Events</option>
          <option value="mouse_click.html">&nbsp;&nbsp;&nbsp;Mouse Click</option>
          <option value="mouse_drag.html">&nbsp;&nbsp;&nbsp;Mouse Drag</option>
          <option value="keyboard.html">Keyboard Events</option>
          <option value="controls.html">Buttons and Sliders</option>
          <option value="files.html">Reading/Writing Files</option>
        </select>
        
      <p class="Normal"><a href="vector.html">Vector operations </a></p>
      <p class="Normal"><a href="graph.html">Graphs</a></p>
    <p class="Normal"><a href="factorial.html">factorial/combin</a></p>
    <p class="Normal">What's new in <a href="new_features.html">Visual 5</a></p>
    <p class="Normal"><a href="http://vpython.org" target="_blank">VPython web site</a><br />
      <a href="license.txt" target="_blank">Visual license</a><br />
      <a href="http://www.python.org" target="_blank">Python web site</a> <br />
      <a href="http://www.python.org/doc/2.5.2/lib/module-math.html" target="_blank">Math module</a> (sqrt etc.)<br />
    <a href="http://www.scipy.org/Documentation" target="_blank">Numpy module</a> (arrays)    </p></td>
    <td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->

        <h1 class="Heading-1"> <font color="#0000A0">Controlling One or More Visual 
          
          Display Windows</font></h1>
      <p class="Normal"> Initially, there is one Visual display window named <span class="attribute">scene</span>. 
        Display objects do not create windows on the screen unless they are used, so 
        if you immediately create your own display object early in your program you 
        will not need to worry about scene. If you simply begin creating objects such 
        as sphere they will go into scene.</p>
        <p class="attributes"> <span class="attribute">display()</span> Creates a display 
          with the specified attributes, makes it the selected display, and returns 
          it. For example, the following creates another Visual display window 600 by 
          200, with its upper left corner at the upper left corner of the screen (y is measured down from the top of the screen), with 'Examples of Tetrahedrons' in the title bar, centered on location (5,0,0), and with 
          a background color of cyan filling the window.</p>

            <p class="program"> scene2 = display(title='<span class="attributes">Examples of Tetrahedrons</span>',<br />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x=0, y=0, width=600, height=200,<br />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;center=(5,0,0), background=(0,1,1))</p>
          <p class="Normal"><strong> <font color="#0000A0">General-purpose options</font></strong></p>
          <p class="attributes"> <span class="attribute">select()</span> Makes the specified 
            display the &quot;selected display&quot;, so that objects will be drawn 
            into this display by default; e.g. <span class="attribute">scene.select() </span></p>
 
            <p class="Normal">Executing <span class="attribute">myscene = </span><font color="#FF0000">display.get_selected()</font> returns
               a reference to the display in which objects are currently being
               created.</p>

          <p class="attributes"> <span class="attribute">foreground</span> Set color 
            to be used by default in creating new objects such as sphere; default is 
            white. Example: <span class="attribute">scene.foreground = (1,0,0)</span> </p>
          <p class="attributes"> <span class="attribute">background</span> Set color 
            to be used to fill the display window; default is black.</p>
          <p class="attributes"><span class="attribute">ambient</span> Color
            of nondirectional  (&quot;ambient&quot;) lighting. Default is color.gray(0.2);
            for compatibility with earlier versions of Visual, this can 
            be expressed as scene.ambient=0.2. </p>
      <p class="attributes"><span class="attribute">lights</span> List of light
            objects created for this display. By default, scene.lights is this list:<br />
            &nbsp;&nbsp;&nbsp;<span class="attribute">[distant_light(direction=(0.22, 0.44, 0.88), color=color.gray(0.8))</span>,<br /> 
            <span class="attribute">&nbsp;&nbsp;&nbsp;distant_light(direction=(-0.88, -0.22, -0.44),
              color=color.gray(0.3))]</span><br />
            These are equivalent to the default lights in Visual prior to version
            5. For how to create your own distant and local lights, see <a href="lights.html">Lighting</a>. <br />
      </p>
          <p class="attributes"><span class="attribute"><font color="#000000">To obtain </font>camera position</span>, see <a href="mouse.html">Mouse Interactions</a>.</p>
          <p class="attributes"><span class="attribute">cursor.visible</span> By
            setting <span class="attribute">scene.cursor.visible = False</span>,
            the mouse cursor  becomes invisible. This is often appropriate while
            dragging an object using  the mouse. Restore the cursor with <span class="attribute">scene.cursor.visible
              = True</span>. Currently has no effect on Linux.</p>
      <p class="attributes"><span class="attribute">objects</span> A list
            of all the visible objects in the display; invisible objects and
            lights are not listed (<span class="attribute">scene.lights</span> is a list of existing lights).
            For example, the following makes all visible boxes in the scene red: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;for obj in scene2.objects: <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if isinstance(obj, box):<br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.color = color.red</p>
          <p class="attributes"><span class="attribute">show_rendertime</span> If you set <span class="attribute">scene.show_rendertime = True</span>, in the lower left corner of the display you will see something like &quot;cycle: 27 render: 5&quot;, meaning 27 milliseconds between renderings of the scene, taking 5 milliseconds to render, in which case 22 out of 27 milliseconds were devoted to executing your Python statements. </p>
      <p class="attributes"><span class="attribute">stereo</span> Stereoscopic
            option; <span class="attribute">scene.stereo = 'redcyan'</span> will
            generate a scene for the left eye and a scene for the right eye,
            to be viewed with red-cyan glasses, with the red lens over the left
            eye. (There are also <span class="attribute">'redblue'</span> and <span class="attribute">'yellowblue'</span> options;
            note that objects that were not originally white may be somewhat
            dim.) <br />
            <br />
Setting <span class="attribute">scene.stereo = 'crosseyed'</span> produces side-by-side
images which if small enough can be seen in 3D by crossing your eyes but focusing
on the screen (this takes some practice). Setting <span class="attribute">scene.stereo
= 'passive'</span> produces side-by-side images which if small enough can be
seen in 3D by looking &quot;wall-eyed&quot;, looking into the far distance but
focusing on the screen (this too takes some practice). <span class="attribute"><br />
            <br />
scene.stereo = 'active'</span> will render alternating left eye/right eye images
for viewing through shutter glasses if the graphics system supports quad buffered
stereo. If stereo equipment is not available, setting the option has no effect,
and <span class="attribute">scene.stereo</span> will have the value <span class="attribute">'nostereo'</span>.
You can also use <span class="attribute">scene.stereo = 'passive'</span> with
quad buffered stereo for display using two polarized projectors (for stereo viewing
using simple passive polarized glasses). (Quad buffered 'active' stereo is only
available on specialised graphics systems that have the necessary hardware and
shutter glass connector, such as PCs with CRT displays and nVidia Quadro graphics
cards. It generates the illusion of depth by rendering each frame twice from
slightly different viewpoints corresponding to the left and right eyes. Special
shutter glasses are synchronised with the alternating images so that each eye
sees only the matching frame, and your brain does the rest. It's called 'quad
buffered' because there is an OpenGL buffer per eye, both double-buffered for
smooth updating. 'Passive' stereo requires a video card that can drive two monitors,
or two projectors.) </p>
          <p class="attributes"><span class="attribute">stereodepth</span> By default, 
            the front of the scene is located at the location of the physical screen, 
            which reduces eye strain. Setting <span class="attribute">scene.stereodepth 
              = 1</span> moves the center of the scene to the location of the physical 
            screen, with the front half of the scene seeming to stick dramatically out 
            of the screen. <span class="attribute">scene.stereodepth = 2</span> moves 
            the scene fully in front of the physical screen, for maximally dramatic 
            stereo effect.</p>
      <p class="Normal"><strong><font color="#0000A0">Controlling the window</font></strong></p>
          <p class="Normal">The window attributes <span class="attribute">x</span>, <span class="attribute">y</span>, <span class="attribute">width</span>, <span class="attribute">height</span>, <span class="attribute">title</span>,
            and <span class="attribute">fullscreen</span> cannot be changed while
            a window is active; they are used to create a window, not to change
            one. If you want to modify any of these window attributes, first
            make the window invisible, make the changes, and then make the window
            visible again. This creates a new window with the new attributes;
            all existing objects are still part of the new window.</p>
          <p class="attributes"> <span class="attribute">x</span>, <span class="attribute">y</span> Position of the window on the screen (pixels from upper left)</p>
          <p class="attributes"> <span class="attribute">width</span>, <span class="attribute">height</span> Width
            and height of the display area in pixels: scene.height = 200 (includes
          title bar). </p>
          <p class="attributes"> <span class="attribute">title</span> Text in the window's 
            
            title bar: scene.title = 'Planetary Orbit'</p>
          <p class="attributes"><span class="attribute">fullscreen</span> Full screen 
            option; <span class="attribute">scene2.fullscreen = True</span><em class="program"> </em> makes the display named <span class="attribute">scene2</span> take 
            up the entire screen. In this case there is no close box visible; press 
            Escape to exit. <br />
            (There is currently a bug in the fullscreen option for Linux; the Escape key has no effect. If you use the 
            fullscreen option on Linux, be sure to program a mouse or keyboard input for 
            quitting the program.)</p>
          <p class="attributes"> <span class="attribute">visible</span> Make
            sure the display is visible; <span class="attribute">scene2.visible
            = True</span><em class="program"> </em> makes the display named <span class="attribute">scene2</span> visible.
            This is automatically called when new primitives are added to the
            display, or the mouse is referenced. Setting <span class="attribute">visible</span> to
            False hides the display.</p>
          <p class="attributes"> <span class="attribute">exit</span> If <span class="attribute">sceneb.exit</span><span class="Body"> is Fals</span><span class="Body">e</span>, the program does not quit when the close box of the <span class="attribute">sceneb</span> display is clicked. The default is <span class="attribute">sceneb.exit = 
              True</span>, in which case clicking the close box does make the program quit. </p>
      <p class="Normal"><strong> <font color="#0000A0">Controlling the view</font></strong></p>
          <p class="attributes"> <span class="attribute">center</span> Location at which 
            
            the camera continually looks, even as the user rotates the position of the 
            
            camera. If you change <span class="attribute">center</span>, the camera 
            
            moves to continue to look in the same &quot;compass&quot; direction toward 
            
            the new center, unless you also change <span class="attribute">forward</span> (see next attribute). Default (0,0,0).</p>
          <p class="attributes"><span class="attribute">autocenter</span> scene.center 
            
            is continuously updated to be the center of the smallest axis-aligned box 
            
            containing the scene. This means that if your program moves the entire scene, 
            
            the center of that scene will continue to be centered in the window.</p>
          <p class="attributes"> <span class="attribute">forward</span> Vector pointing 
            
            in the same direction as the camera looks (that is, from the current camera 
            
            location, given by scene.mouse.camera, toward scene.center). The user rotation 
            
            controls, when active, will change this vector continuously. When <span class="attribute">forward</span> is changed, the camera position changes to continue looking at <span class="attribute">center</span>. 
            
            Default (0,0,-1).</p>
          <p class="attributes"> <span class="attribute">fov</span> Field of view of 
            
            the camera in radians. This is defined as the maximum of the horizontal 
            
            and vertical fields of view. You can think of it as the angular size of 
            
            an object of size range, or as the angular size of the longer axis of the 
            
            window as seen by the user. Default pi/3.0 radians (60 degrees).</p>
          <p class="attributes"> <span class="attribute">range</span> The extent
            of  
            the region of interest away from <span class="attribute">center</span> along
             
            each axis. This is the inverse of scale, so use either <span class="attribute">range</span> or <span class="attribute">scale</span> depending
            on which makes the most
            sense in your program. Setting range to 10 is the same as setting
            it to (10,10,10). Setting range to (10,0,0) means that scene.center+scene.range
            will be at the right edge of a square window. A sphere of radius
            10 will fill the window. A cubical box whose half-width is 10 will
            overfill the window, because the front of the box in 3D appears larger
            than the xy plane passing through scene.center, unless the field
            of view is very small.</p>
          <p class="attributes"> <span class="attribute">scale</span> A scaling
            factor  
            which scales the region of interest into the sphere with unit radius.
            This  
            is the inverse of range, so use either <span class="attribute">range</span> or <span class="attribute">scale</span> depending
            on which makes the most
            sense in your program. Setting scale to 0.1 is the same as setting
            it to (0.1,0.1,0.1) or setting range to (10,10,10).</p>
          <p class="attributes"> &nbsp;<span class="attribute">up</span> A vector representing 
            
            world-space up. This vector will always project to a vertical line on the 
            
            screen (think of the camera as having a &quot;plumb bob&quot; that keeps 
            
            the top of the screen oriented toward up). The camera also rotates around 
            
            this axis when the user rotates &quot;horizontally&quot;. By default the 
            
            y axis is the <span class="attribute">up</span> vector.</p>
          <p class="attributes"> There is an interaction between <span class="attribute">up</span> and <span class="attribute">forward</span>, the direction that the camera 
            
            is pointing. By default, the camera points in the -z direction (0,0,-1). 
            
            In this case, you can make the x or y axes (or anything between) be the <span class="attribute">up</span> vector, but you cannot make the z axis 
            
            be the <span class="attribute">up</span> vector, because this is the axis 
            
            about which the camera rotates when you set the <span class="attribute">up</span> attribute. If you want the z axis to point up, first set <span class="attribute">forward</span> to something other than the -z axis, for example (1,0,0).</p>
          <p class="attributes"> <span class="attribute">autoscale = False</span> no automatic 
            
            scaling (set range or scale explicitly);<span class="attribute">&nbsp;autoscale 
              
              = True</span> automatic scaling (default). It is often useful to let Visual 
            
            make an initial display with autoscaling, then turn autoscaling off to prevent 
            
            further automated changes.</p>
          <p class="attributes"> <span class="attribute">userzoom = False</span> user cannot zoom in and out of the scene</p>
          <p class="attributes"><span class="attribute">userzoom = True</span> user can zoom (default)</p>
          <p class="attributes"> <span class="attribute">userspin = False</span> user cannot rotate the scene</p>
          <p class="attributes"> <span class="attribute">userspin = True</span> user can rotate (default)</p>

<!-- InstanceEndEditable --></td>
  </tr>
  <tr>
    <td height="16" colspan="4"></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>