image thumbnail
from Light show by Tim Streeter
Light sources float around stationary spheres.

sample_light_show
% -------------------------------------------------------------------------
% sample_light_show
% -------------------------------------------------------------------------
% This example renders 3 lights floating around and through 2 larger, concentric
% spheres.  If the animation is sluggish, either reduce the number of lights
% (LINE 19) or reduce the number of points used to render the large
% stationary spheres (LINE 25).
% -------------------------------------------------------------------------
% T. Streeter, 19 DEC 2006
% -------------------------------------------------------------------------
function sample_light_show

close all

number_of_frames=1000;

%Set light source parameters:
%----------------------------
number_of_lights=3; %sphere matrix size for moving lights
light_sphere_points=10; %sphere matrix size for moving light spheres
light_source_radius=.1; %light source radius

%Set stationary sphere parameters:
%---------------------------------
large_sphere_points=50; %sphere matrix size (N+1 by N+1) for stationary spheres
large_sphere_colors(1,:)=[1 1 1]; %color of sphere 1
large_sphere_colors(2,:)=[.5 .5 .5]; %color of sphere 2
large_sphere_radius=[1 2];
large_sphere_transparency=[.5 .5];

%Generate light color list:
%--------------------------
cvec_0=hwrect(1-(((1:number_of_lights)*2)/number_of_lights-2/number_of_lights)); %first generate the red
light_colors(1,:)=cvec_0; %fill red
light_colors(2,1:ceil(number_of_lights/2))=cvec_0(ceil(number_of_lights/2):-1:1); %fill green first half
light_colors(2,floor(number_of_lights/2)+1:number_of_lights)=cvec_0(1:ceil(number_of_lights/2)); %fill green second half
light_colors(3,:)=fliplr(cvec_0); %fill blue
light_colors=light_colors';
clear cvec_0;

light_show(large_sphere_points,large_sphere_colors,...
    large_sphere_radius,large_sphere_transparency,...
    number_of_lights,light_sphere_points,light_source_radius,...
    light_colors,number_of_frames);

%--------------------------------------------------------------------------
%Function used to generate light colors:
%--------------------------------------------------------------------------

function y=hwrect(x);
y=(abs(x)+x)/2;

Contact us at files@mathworks.com