Swinging, Flickering Light


With these expressions we'll simulate a swinging light that is flickering. The cord drives the animation. It is a narrow solid with its anchor point moved up and off-screen.The shade and the light bulb are parented to the cord

Then I added a spot light and parented it to the cord also. The bulb and the light need to be positioned such that the light will illuminate the bulb.

Add the following expression to the intensity parameter of the light:


min_seg = 1.5; //minimum interval (must be > 0) 
max_seg = 2.5; //maximum interval (must be > min_seg) 
min_flicker = .5; //must be less than min_seg 
max_flicker = 1; // must be less than min_seg 

seg_start_time = 0; //initial conditions 
seg_end_time = 0; 
i =1; 

while (time >= seg_end_time){ 
  i = i+1; 
  seed_random(i,true); 
  seg_start_time = seg_end_time; 
  seg_end_time = seg_end_time + random(min_seg,max_seg); 
} 

flicker_dur = random(min_flicker,max_flicker); 
if (time > seg_end_time - flicker_dur){ 
seed_random(1,false); 
random(0,100); 
} 
else{ 
100; 
}

Add an expression like this to the rotation property of the cord to generate a nice, gentle swaying motion:


amplitude=7;
period=3; //seconds

amplitude*Math.sin(time*Math.PI*2/period)

Adjust amplitude and period as necessary.