question

Noah Z avatar image
1 Like"
Noah Z asked Noah Z commented

Background Brightness Changes by Time of Day?

I have a model I'm building of an outside location. For fun I was thinking about if it is possible to change the brightness/lighting levels in the model as a function of the time of day? Has anyone done this before? It would simply be an aesthetic improvement and have no impact on results but might add a nice touch of realism if it got darker during the night hours.

FlexSim 18.0.3
visual displaybrightness
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Noah Z commented

In this sample model, I'm using code in the OnDraw trigger to adjust the color of the ambient light and light sources. The lights go up when the model starts and then go dark about 12 hours later, staying dark for the next 12 hours.

daylightdemo.fsm

It uses this code in the draw trigger:

Object current = ownerobject(c);
treenode view = param(1);

/**Adjust Light based off time of day*/

treenode viewSettings = view.find(">viewsettings");
treenode ambient = viewSettings.find("viewambient");
treenode lights = viewSettings.find("viewlights");

int secsPerDay = 60*60*24;
double percentDaylight = 3 * sin(2*pi() * ((time() % secsPerDay) / secsPerDay));
percentDaylight = min(1, max(0, percentDaylight));

for(int i = 1; i <= 3; i++)
	ambient.subnodes[i].value = 0.2 * percentDaylight;
	
for(int i = 1; i <= lights.subnodes.length; i++) {
	treenode light = lights.subnodes[i];
	double lightVal = 0.4 * percentDaylight;
	light.subnodes["viewlightr"].value = lightVal;
	light.subnodes["viewlightg"].value = lightVal;
	light.subnodes["viewlightb"].value = lightVal;
}

daylightdemo.fsm (21.5 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Noah Z avatar image Noah Z commented ·

Very nice! This is exactly the type of thing I had in mind. Thank you!

0 Likes 0 ·