This is the best I could do based soley on sun angle. It publishes normalized numbers as properties for scenery objects to use in material animations. This allows night lighting. The properties come on slowly, so there is no sudden jarring flickering of lights across the entire city at once. There are three to chose from, each slightly offset.
If the ambient light level is ever exposed, I will re-write this in a more elegant fashion. Josh
# lighting.nas # # Josh Babcock 2006 # Released under the GPL # # provide some properties to be used by scenery objects for night lighting. # At some point FG will hopefully expose the amount of ambient light as a property # at which point this can all be re-written. thresholds = { "night":1.75, "evening":1.55, "transit":1.54, "twilight":1.34 }; sun = nil; transition = 0.1; frequency = 1; # base = props.globals.getNode("/sim/model/global/lighting", 1) init = func { sun = props.globals.getNode("/sim/time/sun-angle-rad", 1); # print("lighting.nas initialized"); settimer(main, 0); } main = func { foreach (period; keys(thresholds)) { angle_below_threshold = sun.getValue() - thresholds[period]; if ( angle_below_threshold >= 0 ) { # night setprop("/sim/model/global/lighting/"~period, 1); } elsif ( angle_below_threshold > transition ) { # transition setprop("/sim/model/global/lighting/"~period, angle_below_threshold/transition); } else { # day setprop("/sim/model/global/lighting/"~period, 0); } } settimer(main, frequency); } settimer(init, 0);