If you're new to Python
A VPython tutorial
Pictures of 3D objects
Studying this description of the cylinder object provides an overview of important aspects common to all of the VPython 3D objects, box, sphere, pyramid, etc. Additional details about how to orient an object using "axis" and "up" are found in the description of the box object.
Here is an example of how to make a cylinder, naming it "rod" for future reference:
rod = cylinder(pos=vector(0,2,1), axis=vector(5,0,0), radius=1)
The center of one end of this cylinder is at x=0, y=2, and z=1. Its axis lies along the x axis, with length 5, so that the other end of the cylinder is at (5,2,1), as shown in the accompanying diagram.
You can modify the position of the cylinder after it has been created, which has the effect of moving it immediately to the new position:
rod.pos = vector(15,11,9)
If you create an object such as a cylinder but without giving it a name such as rod, you can't refer to it later. This doesn't matter if you never intend to modify the object.
Since we didn't specify a color, the cylinder will be the current "foreground" color (see Controlling One or More VPython Canvases). The default foreground color is white. After creating the cylinder, you can change its color:
rod.color = vector(0,0,1) # make rod be blue
This will make the cylinder suddenly turn blue, using the so-called RGB system for specifying colors in terms of fractions of red, green, and blue. (For details on choosing colors, see Specifying Colors.) You can set individual amounts of red, green, and blue like this:
rod.red = 0.4
The cylinder object can be created with other, optional attributes, which can be listed in any order. Here is a full list of attributes, most of which also apply to other objects:
pos Position: the center of one end of the cylinder; default = vector(0,0,0)
axis The axis points from pos to the other end of the cylinder, default = vector(1,0,0). Setting the axis makes length equal to the magnitude of the axis. An object's axis and up attributes are always perpendicular to each other. Changing the direction of axis also changes the direction of up so that the two directions always remain at right angles to each other.
up Which side of the cylinder is "up"; this has only a subtle effect on the 3D appearance of the cylinder unless a non-smooth texture is specified or the cross section is oval; the default is vector(0,1,0). An object's axis and up attributes are always perpendicular to each other. Changing the direction of up also changes the direction of axis so that the two directions always remain at right angles to each other.
length Length of axis and x component of size; default is 1. Setting the length makes the magnitude of the axis equal to the length.
radius The radius of the cylinder, default = 1
size Instead of specifying length and radius, you can set size=vector(length,height,width), which means that the cross section of the cylinder can be elliptical, which is not currently possible in classic VPython. Setting size makes the magnitude of axis be equal to the x component of the size (the length).
color Color of object, as a red-green-blue (RGB) triple: vector(1,0,0) is pure red, default = vector(1,1,1), which is color.white
red, green, blue (can set these color attributes individually), defaults are all 1
opacity Opacity of object, default = 1; 0 is completely transparent
shininess 0 to 1, default 0.6; governs the amount of specular reflections.
emissive If True, local and distant lights are ignored, and the brightness is governed by the object's own color. An example of its use is to put an emissive sphere at the location of a local_light, which looks like a glowing lamp. The default for emissive is False.
texture Texture of object; see Textures for currently available options (there are no materials in the GlowScript version of VPython, but textures are similar)
Note that the pos attribute for cylinder, arrow, cone, and pyramid corresponds to one end of the object, whereas for a box, sphere, or ring it corresponds to the center of the object.
If you include make_trail=True when you create the object, a trail will be left behind the object as you move it. For related options, see Leaving a Trail.
See Rotating an Object for an easy way to change the orientation of an object.
See description of Additional Attributes available for all 3D display objects.
When you start a VPython program, for convenience VPython creates a canvas and names it scene. By default, objects that you create go into that canvas. See Controlling One or More VPython Display Windows later in this reference for how you can create additional canvases and place objects in them.