Home

If you're new to Python
and VPython: Introduction

A VPython tutorial

Pictures of 3D objects

What's new in VPython 6

VPython web site
VPython license
Python web site
Math module (sqrt etc.)
Numpy module (arrays)

 
Lighting
material etc

You can light a scene with distant lights (which act like point-like lamps far from the scene) and/or local lights (point-like lamps near the scene, like the yellow light shown above). For a distant light you specify its direction from the origin. For a local light you specify its location in the scene.

There is a list of all distant and local light objects, scene.lights. By default, scene.lights is this list:

[distant_light(direction=(0.22, 0.44, 0.88),       color=color.gray(0.8)),
 distant_light(direction=(-0.88, -0.22, -0.44),       color=color.gray(0.3))]

These are equivalent to the default lights in VPython prior to version 5. You can get rid of these default lights by setting the list to empty with scene.lights = [].

In addition to these default distant lights, there is default ambient lighting in the form of scene.ambient=color.gray(0.2); for compatibility with earlier versions of Visual, this can be expressed as scene.ambient=0.2, but now the ambient light can be specified as any color you want. The color of light objects and the amount of scene.ambient must be specified with some care, because if the total lighting intensity exceeds 1 anywhere in the scene the results are unpredictable.

The following statement creates a local yellow light whose position is at (x,y,z), and if you continually update lamp.pos, the light will move. You may wish to place a sphere or box with material=materials.emissive at the same location so that the lamp looks like a glowing lamp.

lamp = local_light(pos=(x,y,z), color=color.yellow)

A distant red light located in the direction (x,y,z) from the origin is created like this:

distant_light(direction=(x,y,z), color=color.red)

Previous to VPython 5, you set up a light by specifying a vector in the direction to the light from the origin, and the magnitude of the vector was the intensity. For example, scene.lights = [vector(1,0,0)] with scene.ambient = 0 would light the scene with full intensity from the right side, with no ambient lighting. In VPython 5 and later, this scheme for specifying lights still works, but this compatibility syntax actually creates distant_light objects.