-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtext.html
More file actions
227 lines (222 loc) · 15.5 KB
/
text.html
File metadata and controls
227 lines (222 loc) · 15.5 KB
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
<!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="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>text</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<style type="text/css">
<!--
.style2 {
font-size: x-large;
font-weight: bold;
}
.style2 {font-size: xx-large}
-->
</style>
<!-- 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--> </td>
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p> </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 an 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="extrusion.html">extrusion</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>
<option value="text.html">text</option>
</select>
<p class="Normal">Work with objects:</p>
<select name="jumpMenu4" id="jumpMenu5" onchange="MM_jumpMenu('parent',this,0)">
<option>Choose an option</option>
<option value="color.html">Color/Opacity</option>
<option value="materials.html">Materials/Textures</option>
<option value="shapes.html">Shapes Library</option>
<option value="paths.html">Paths Library</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>
<option value="controls.html">Buttons/Sliders</option>
<option value="graph.html">Graphs</option>
<option value="lights.html">Lighting</option>
<option value="files.html">Read/Write Files</option>
<option value="trail.html">Leaving a Trail</option>
<option value="vector.html">Vector Operations </option>
<option value="factorial.html">factorial/combin</option>
</select>
<p class="Normal">Windows & Events:</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="mouse.html">Mouse Events</option>
<option value="mouse_click.html"> Mouse Click</option>
<option value="mouse_drag.html"> Mouse Drag</option>
<option value="keyboard.html">Keyboard Events</option>
</select>
<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--> </td>
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
<table width="100%" border="1">
<tr>
<td width="62%"><div align="center"><span class="style2"><font color="#0000A0">text</font></span></div></td>
<td width="38%"><div align="center"><img src="images/text3d.jpg" width="233" height="183" alt="text" /><a href="arrow.html"></a></div></td>
</tr>
</table>
<p class="Normal"><img src="images/text.jpg" width="635" height="364" alt="text" /></p>
<p class="Normal"> With the text object you can display 3D text. The
green 3D text shown above was created with the following statement:</p>
<p class="program"> text(text='My text is\ngreen',<br />
align='center', depth=-0.3, color=color.green) </p>
<p class="Normal">Labels were added to the display above to illustrate
some of the main attributes of the text object; the full program
text3d.py can be seen in the VPython examples. Whether you extrude into or out of the screen, the text is created so that it is readable left to right from the normal viewing position, in the +z direction. If you wish to position the text differently, change the <span class="attribute">axis</span> from its default value of (1,0,0).</p>
<p class="Normal">Here
is a list of text attributes:</p>
<p class="attributes"> <span class="attribute">pos</span>; <span class="attribute">x</span>,<span class="attribute">y</span>,<span class="attribute">z</span> The
location of the baseline of the text, to the left, to the right,
or at the center of the text, as per align.<span class="attribute"></span><span class="attribute"></span></p>
<p class="attributes"> <span class="attribute">align </span>Specify 'left'
(default), 'right', or 'center'.</p>
<p class="attributes"> <span class="attribute">text</span> The text to
be displayed, such as My Text in the example above.
Python Unicode strings are supported. Currently it is not possible to display
more than a single line of text with one text object.</p>
<p class="attributes"> <span class="attribute">font</span> Name of
the desired font; for example, 'sans', or 'serif' (default), or
'monospace' (fixed-width). You can also give specific names such
as "Times" or "Verdana". An attempt is made
to find a font name that best matches the name you specify. If
there is no match, font defaults to 'sans'.</p>
<p class="attributes"> <span class="attribute">height</span> Height
of an uppercase letter (see above); default is 1. Specifying the
height and depth sets the scale for the entire text display. Changing
the height also changes descent and vertical_spacing, but not depth.</p>
<p class="attributes"><span class="attribute">depth</span> Depth
of the text, which can be a single number or a vector. For a single
number, positive means extrude toward you, out of the screen; negative
means extruded away from you, into the screen. For a vector, the
text is extruded in the direction of the vector. Default depth
is 0.2.</p>
<p class="attributes"><span class="attribute">width</span> Width
of the displayed text. This is "read-only" and is determined
by the text. Also, <span class="attribute">widths</span> is a list
of the widths of all lines of text, so <span class="attribute">widths[0]</span> is
the width of the top line, etc.</p>
<p class="attributes"><span class="attribute">axis</span> The axis
points along the baseline; changing the axis changes the orientation
of text. The axis is normalized to have a length of 1. The default is (1,0,0), with text going toward the right.</p>
<p class="attributes"><span class="attribute">descent</span> Height
of the descender on lower-case letters such as y (whether or not
there is such a letter in the text). This is typically about 0.3
times the height. This is read-only.</p>
<p class="attributes"><span class="attribute">vertical_spacing</span> Vertical
distance from one baseline to the next in a multiline text. The
default is set by the font you use, but you can override this by
changing the value.</p>
<p class="attributes"> <span class="attribute">color</span>, <span class="attribute">red</span>, <span class="attribute">green</span>, <span class="attribute">blue</span> Color
of the text.</p>
<p class="attributes"> <span class="attribute">material</span> Material
such as materials.wood.</p>
<p class="attributes"> <span class="attribute">upper_left, upper_right,
lower_right, lower_left </span>The bounding box of the displayed
text; all of these are read-only. For example, if you create
<span class="program"><strong>title = text(text="My Text")</strong></span>,
you can place a sphere at the upper left corner with the statement
<strong>sphere(pos=title.upper_left</strong>).
While <span class="attribute">height</span> and <span class="attribute">descent</span> indicate
the general properties of the selected font, <span class="attribute">upper_left</span> etc.
tell you the bounding box of the actual text. For example, if the
text is "ABC", <span class="attribute">lower_left</span> will
be at the same height as <span class="attribute">start</span>
because there are no descenders, and if the text is "mno", <span class="attribute">upper_left</span> will
be less than <span class="attribute">height</span> above the baseline
because
there are no upper-case letters.</p>
<p class="attributes"> <span class="attribute">start</span> The left-most
location on the baseline. This is read-only. Also, <span class="attribute">starts</span> is
a list of the starts of all lines of text, so <span class="attribute">starts[0]</span> is
the start of the top line, etc.</p>
<p class="attributes"> <span class="attribute">up</span> Controls
the up attribute of the frame; changing up makes the text tip away
from the vertical. </p>
<p class="attributes"> <span class="attribute">spacing</span> Makes
space between letters, specified as a fraction of height (default
is 0.03).</p>
<p class="attributes"><span class="attribute">twosided</span><span class="Normal"> A text object is a complex object that can take longer to render onto the screen than other objects, due to the many calculations required to generate the triangles and normals required for the display. Like all other objects (except for faces), a text object by default is two-sided (so that you see interior "walls" if you zoom inside the object). One way to get a significant speed-up is to make the object not be two-sided, by setting </span><span class="attribute">twosided = False</span><span class="Normal">.</span></p>
<p class="Normal"></p>
<p class="Normal">The following code will list the True Type fonts
on your system that can be used with a text object:</p>
<p class="program">fonts = <span class="Normal">shapes.findSystemFonts</span>()<br />
for f in fonts:
<br />
print(f)</p>
<p class="Normal"><strong><font color="#0000a0">Extracting extrusion data</font></strong></p>
<p class="Normal">The following statement provides the <span class="attribute">pos</span>, <span class="attribute">normal</span>, and <span class="attribute">color</span> information needed for creating a single-sided faces object:</p>
<p class="program">(pos, normal, color) = T.get_faces()</p>
<p class="Normal">You can convert a text object directly to a faces object, though this has the disadvantage that you lose the ability to change the text attributes dynamically:</p>
<p class="program">T = text(.....)<br />
F = E.create_faces() # produces an equivalent faces object</p>
<p class="Normal">The conversion routine makes the text object invisible and by default destroys its contents. If you wish to keep the text object for later modification, say <span class="code"><strong>E.create(keep=True)</strong></span>. </p>
<p class="Normal">The faces object uses much more memory than the equivalent text object, and it may actually take as long or longer to render. The effect on the speed depends on the details of the text object and the platform you're using. If <strong>scene.show_rendertime = True</strong> you can see the "cycle" time in milliseconds between renderings, both before and after conversion. Approximately half of the cycle time is devoted to rendering the scene, and about half to your own computations. Longer cycle times reflect longer render times; the minimum cycle time is about 30 milliseconds (about 30 renderings per second). If the scene is not very complicated, very little time is needed to render the scene, and almost all the time is given to your computations.</p>
<p class="Normal">The <strong>create_faces()</strong> function uses the <strong>get_faces()</strong> function but also copies into the faces object the <span class="attribute">frame</span>, <span class="attribute">material</span>, and <span class="attribute">up</span> attributes of the text object, makes the extrusion object invisible, and destroys its contents (unless you specify that <span class="attribute">keep=True</span>).</p>
<p class="Normal">See description of <a href="options.html">Additional
Attributes</a> available for all 3D display objects.</p>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td height="16" colspan="4"></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>