IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Description of Objects in VPython

The label Object

With the label object you can display text in a box. Here are simple examples (in the second label statement, note the standard Python scheme for formatting numerical values, where 1.5f means 1 figure before the decimal point and 5 after):

box(pos=(0,0,0), color=color.red)

label(pos=(0,0.25,0), text='This is a box')

label(pos=(0,-0.25,0), text='pi = %1.5f' % pi)

There are many additional label options. In the accompanying diagram, a sphere representing the Earth (whose center is at earth.pos) has an associated label carrying the text "Earth" in a box, connected to the sphere by a line which stops at the surface of the sphere:

earthlabel = label(pos=earth.pos, text='Earth', xoffset=20, yoffset=12, space=earth.radius, height=10, border=6)

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; x,y,z The point in world space being labeled

xoffset, yoffset The x and y components of the line, in pixels (see diagram)

text The text to be displayed, such as 'Earth'
(Line breaks can be included as \n, as in label.text = "Three\nlines\nof text")

height Height of the font in pixels

color, red, green, blue Color of the text

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

box 1 if the box should be drawn (default), else 0

line 1 if the line from the box to pos should be drawn (default), else 0

linecolor Color of the line and box

space World-space radius of a sphere surrounding pos,
into which the connecting line does not go

font Optional name of the font, such as `helvetica'