MATLAB Functions Help Desk

light

Purpose

Create a Light object

Syntax

Description

light creates a Light object in the current Axes. Lights affect only Patch and Surface object.

light('PropertyName',PropertyValue,...) creates a Light object using the specified values for the named properties. MATLAB parents the Light to the current Axes unless you specify another Axes with the Parent property.

Remarks

You cannot see a Light object per se, but you can see the effects of the light source on Patch and Surface objects. You can also specify an Axes-wide ambient light color that illuminates these objects. However, ambient light is visible only when at least one Light object is present and visible in the Axes.

You can specify properties as property name/property value pairs, structure arrays, and cell arrays (see the set and get reference pages for examples of how to specify these data types).

See also the Patch and Surface AmbientStrength, DiffuseStrength, SpecularStrength, SpecularExponent, SpecularColorReflectance, and VertexNormals properties.

Examples

Light the peaks Surface with a light source located at infinity and oriented along the direction defined by the vector [1 0 0], that is, along the x-axis.

Object Hierarchy



Setting Default Properties

You can set default Light properties on the Axes, Figure, and Root levels:

Where Property is the name of the Light property and PropertyValue is the value you are specifying.

Light Properties

This section lists property names along with the type of values each accepts.

BusyAction             cancel | {queue}

Callback routine interruption. The BusyAction property enables you to control how MATLAB handles events that potentially interrupt executing callback routines. If there is a callback routine executing, subsequently invoked callback routes always attempt to interrupt it. If the Interruptible property of the object whose callback is executing is set to on (the default), then interruption occurs at the next point where the event queue is processed. If the Interruptible property is off, the BusyAction property (of the object owning the executing callback) determines how MATLAB handles the event. The choices are:

ButtonDownFcn          string

This property is not useful on Lights.

Children               handles

The empty matrix; Light objects have no children.

Clipping               on | off

Clipping has no effect on Light objects.

Color                  ColorSpec

Color of Light. This property defines the color of the light emanating from the Light object. Define it as three-element RGB vector or one of MATLAB's predefined names. See the ColorSpec reference page for more information.

CreateFcn              string

Callback routine executed during object creation. This property defines a callback routine that executes when MATLAB creates a Light object. You must define this property as a default value for Lights. For example, the statement,

sets the current Figure colormap to hsv whenever you create a Light object. MATLAB executes this routine after setting all Light properties. Setting this property on an existing Light object has no effect.

The handle of the object whose CreateFcn is being executed is accessible only through the Root CallbackObject property, which can be queried using gcbo.

DeleteFcn              string

Delete Light callback routine. A callback routine that executes when you delete the Light object (i.e., when you issue a delete command or clear the Axes or Figure containing the Light). MATLAB executes the routine before destroying the object's properties so these values are available to the callback routine.

The handle of the object whose DeleteFcn is being executed is accessible only through the Root CallbackObject property, which can be queried using gcbo.

HandleVisibility       {on} | callback | off

Control access to object's handle by command-line users and GUIs. This property determines when an object's handle is visible in its parent's list of children. Handles are always visible when HandleVisibility is on. When HandleVisibility is callback, handles are visible from within callbacks or functions invoked by callbacks, but not from within functions invoked from the command line - a useful way to protect GUIs from command-line users, while permitting their callbacks complete access to their own handles. Setting HandleVisibility to off makes handles invisible at all times - which is occasionally necessary when a callback needs to invoke a function that might potentially damage the UI, and so wants to temporarily hide its own handles during the execution of that function.

When a handle is not visible in its parent's list of children, it can not be returned by any functions which obtain handles by searching the object hierarchy or querying handle properties, including get, findobj, gca, gcf, gco, newplot, cla, clf, and close. When a handle's visibility is restricted using callback or off, the object's handle does not appear in its parent's Children property, Figures do not appear in the Root's CurrentFigure property, objects do not appear in the Root's CallbackObject property or in the Figure's CurrentObject property, and Axes do not appear in their parent's CurrentAxes property.

The Root ShowHiddenHandles property can be set to on to temporarily make all handles visible, regardless of their HandleVisibility settings (this does not affect the values of the HandleVisibility properties).

Handles that are hidden are still valid. If you know an object's handle, you can set and get its properties, and pass it to any function that operates on handles. This property is useful for preventing command-line users from accidently drawing into or deleting a Figure that contains only user interface devices (such as a dialog box).

Interruptible          {on} | off

Callback routine interruption mode. Light object callback routines defined for the DeleteFcn property are not affected by the Interruptible property.

Style                  {infinite} | local

Parallel or divergent light source. This property determines whether MATLAB places the Light object at infinity, in which case the light rays are parallel, or at the location specified by the Position property, in which case the light rays diverge in all directions. See the Position property.

Parent                 handle of parent Axes

Light objects parent. The handle of the Light object's parent Axes. You can move a Light object to another Axes by changing this property to the new Axes handle.

Position               [x,y,z] in Axes data units

Location of Light object. This property specifies a vector defining the location of the Light object. The vector is defined from the origin to the specified x, y, and z coordinates. The placement of the Light depends on the setting of the Style property:

Selected               on | off

This property is not used by Light objects.

SelectionHighlight     {on} | off

This property is not used by Light objects.

Tag                    string

User-specified object label. The Tag property provides a means to identify graphics objects with a user-specified label. This is particularly useful when constructing interactive graphics programs that would otherwise need to define object handles as global variables or pass them as arguments between callback routines. You can define Tag as any string.

Type                   string (read only)

Type of graphics object. This property contains a string that identifies the class of graphics object. For Light objects, Type is always 'light'.

UserData               matrix

User specified data. This property can be any data you want to associate with the Light object. The Light does not use this property, but you can access it using set and get.

Visible                {on} | off

Light visibility. While Light objects themselves are not visible, you can see the light on Patch and Surface objects. When you set Visible to off, the light emanating from the source is not visible. There must be at least one Light object in the Axes whose Visible property is on for any lighting features to be enabled (including the Axes AmbientLightColor and Patch and Surface AmbientStrength).

See Also

lighting, material, patch, surface



[ Previous | Help Desk | Next ]