Home Pictures of 3D objects
text

3D text

See the Text Output discussion for additional ways to output text in the GlowScript environment.

With the text object you can display 3D text. The green 3D text shown above was created with the following statement:

text(text='My text is\ngreen',
    align='center', depth=-0.3,
    color=color.green)

Labels were added to the display above to illustrate some of the main attributes of the text object. 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.

3D text is made out of quads and triangles which are then made into a compound object for speed of display. You can make additional copies of a text object by cloning it. You can move the text by specifying a new pos, and you can change its size, axis, up, color, opacity, shininess, and emissive, as with other objects, but note that color and size are "multiplicative"; see compound.

Here is a list of text attributes, in addition to the usual attributes of canvas, color, shininess, and opacity (but not texture or bumpmap, currently):

pos The location of the baseline of the text, to the left, to the right, or at the center of the text, as per align.

align Specify 'left' (default), 'right', or 'center'.

text The text to be displayed, such as "My text is\ngreen" in the example above ('\n' is a new line character). Unicode strings are supported. After creating the object, the text is read-only -- it cannot be changed. The reason for this is that it takes a significant portion of a second to create a 3D text object. If you need to change the text, make the current object invisible (visible=False) and create a new object.

font Name of the desired font, either "sans" (sans serif, the default) or "serif". This is read-only.

billboard In computer graphics "billboard" behavior means that the object always faces you, no matter how you reorient the camera. Specifying billboard = True when creating the text turns this on, and then is read-only. Because lighting changes as you rotate the camera, you may wish to specify emissive = True, so that the text is always bright.

height 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.After creating the 3D text, you can change the height. For example, if you say T.height = 0.5*T.height, the letters become shorter but the length stays the same.

length length of the displayed text. After creating the 3D text, you can change this. For example, if you say T.length = 0.5*T.length, the letters become narrower but the height stays the same.

depth Depth of the text; the default is 0.2 times the height. A positive number means extrude toward you, out of the screen; negative means extruded away from you, into the screen. After creating the 3D text, you can change this. For example, if you say T.depth = 2*T.length, the letters become twice as thick. If the depth is zero, the thickness is made to be 0.01 times the height, and the text looks like a thin sheet.

descender 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 but is affected by changes in height.

upper_left, upper_right, lower_right, lower_left The bounding box of the displayed text; all of these are read-only. For example, if you create title = text(text="My Text"), you can place a sphere at the upper left corner with the statement sphere(pos=title.upper_left).

start, end The left-most and right-most locations on the baseline. These are read-only. If align is 'left', pos is the same as start. If align is 'right', pos is the same as end.

vertical_spacing Vertical distance from one baseline to the next in a multiline text. This is read-only.

size You change the size, which does not affect the axis. The size is multiplicative, as the text object is actually a compound object; see the documentation on compound objects.

axis The axis points along the baseline; changing the axis changes the orientation of text. The default is (1,0,0), with text going toward the right. Changing the axis only affects the direction of the line of text, not the length or size. up Controls the up attribute of the frame; changing up makes the text tip away from the vertical

up Controls the up attribute of the text; changing up makes the text tip away from the vertical.

Top of page