If you're new to Python
and VPython see more
Help at glowscript.org

Pictures of 3D objects


With the label object you can display text in a box, and the label always faces forward, even if you rotate the scene (for 3D text, see the text object). Here is a simple example:

label( pos=vec(0,0.25,0), text='Hello!' )

label There are many additional label options. In the diagram to the right, an object located at "obj.pos" has an associated label with the text "Early" in a box, connected to the object.

L = label(pos=obj.pos,
    text='Early', xoffset=20,
    yoffset=50, space=30,
    height=16, border=4,

A unique feature of the label object is that several attributes are given in terms of screen pixels instead of the usual "world-space" coordinates. For example, the height of the text is given in pixels, with the result that the text remains readable even when the sphere object is moved far away. Other pixel-oriented attributes include xoffset, yoffset, and border. Here are the label attributes:

pos The point in world space being labeled.

pixel_pos If True, pos is the position in terms of pixels, with vec(0,0,0) in the lower left corner.

align Specify 'left', 'right', or 'center'. When you specify 'center', which is the default, the center of the topmost line of text is at the location given by pos. When you specify 'left', the start of the topmost line of text is at the location given by pos. When you specify 'right', the right end of the topmost line of text is at the location given by pos.

xoffset, yoffset The x and y components of the line, in pixels (see diagram). Unless you specify a value for align, text above or below pos is centered, text to the left of pos is right-adjusted, and text to the right of pos is left-adjusted.

text The text to be displayed, such as 'Earth'. You can give a number or numerical expression; it will be converted to a string.You can include the HTML styles for italic (<i> or <em>), bold (<b> or <strong>), superscript (<sup>), or subscript (<sub>). For example, the string
     'The <b>mass <i>M</i></b><sub>sys</sub> = 10<sup>3</sup> kg.
displays as
    'The mass Msys = 103 kg.

Multiple lines can be displayed by inserting line breaks (\n), as in "Three\nlines\nof text" and you can insert <br> or <br/> instead of \n. You can also create multiple lines by using triple quotes:

        L = label()
        L.text = """The quick brown fox
        jumps over the lazy dog."""

font Name of the desired font; 'sans' or 'serif'' or 'monospace' (fixed-width), or a specific font name; the default is "sans"

height Height of the font in pixels; default is 15 pixels

color Color of the text; default is scene.foreground

background Color of the background of the box; default is scene.background

opacity Opacity of the background of the box, default 0.66
(0 transparent, 1 opaque, for objects behind the box)

border Distance in pixels from the text to the surrounding box; default is 5 pixels

box True if the box should be drawn (default), else False

line True if a line from the pos to the box should be drawn (default), else False

linecolor Color of the line and box

linewidth Thickness of the line drawn from the pos to the box, and the edges of the box (default is 1 pixel)

space Radius in pixels of a sphere surrounding pos, into which the connecting line does not go

visible Label is not displayed if False

See description of Additional Attributes available for all 3D display objects.