Using Timers With Lights

You can use the timer to fade a light in and out or change its color, using the diffuse message. First, lets try using a timer to move a light.

object file: whiteroom.pfb

#include "User0"

object (file("whiteroom.pfb"))

// a light moving up and down
light whitelight (position(0 0 5 1))

timer (duration(5),startValue(0),endValue(10),start,
	when(changed,whitelight.position(0 0 $value 1)),
	when(back,reverse),
	when(front,forward))

Now let's animate the color instead. The diffuse message takes 3 arguments, float values for red, green and blue, on a range of 0 to 1. This example will make the light fade to red, then back to black.

// a light turning on and off
light redlight (position(0 0 7 1),diffuse(0 0 0))
timer (duration(5),startValue(0),endValue(1),start,
	when(changed,redlight.diffuse($value 0 0)),
	when(back,reverse),
	when(front,forward))
	

Giving the timer 3 variables, we can smoothly fade between two colors.

// a light changing between two colors

light mylight (position(0 0 7 1),diffuse(1 0 .3))
timer (duration(5),startValues(1 0 .3),endValues(0 1 .3),start,
	when(changed,mylight.diffuse($value $value1 $value2)),
	when(back,reverse),
	when(front,forward))

(c) Ben Chang