Friday, August 15, 2014

Fireflies

Against the Night Sky Fireflies Look Rather Like Stars,
If Stars were Yellowish-Green and Flashed  Intermittently

One of the earliest scripts I came across in Second Life is called Foxfire. It was created by Ama Omega, whose birth date in Second Life was 12/11/2002. Foxfire produces briefly-flashing tiny yellow lights throughout the brief Second Life night. I immediately modified it so fireflies would appear both day and night. Since 2008 I  have had dozens of copies stuffed into prims all over Whimsy and Whimsy Kaboom.

Sweetie didn't say much about the fireflies until lately, when she complained they weren't the right color. "Fireflies aren't bright yellow," she said. "They're greenish yellow."

She was right, of course.

I rezzed a prim, put the Foxfire script in it, and asked her to color the prim to a firefly color she could live with. She did, and I changed the particle start and end colors in the script to produce a proper firefly color.

Next, we increased the radius of the firefly display from 3.0 to 4.5 meters and halved the number of fireflies visible at any one time. We also tweaked the length of time each flash was visible. When we were finished, the field of fireflies appeared across a greater distance, was not so densely populated, and produced flashes of a realistic length and color.

Finally, Sweetie convinced me it would be better to reset the fireflies so they appeared only during the Second Life night.

"But people set the sun position all sorts of ways," I complained. "Some have noon on all the time. Some, like you, live at midnight."

"True," she said, "but Whimsy is optimized to provide spectacular experiences at both day and night. We should let visitors know that."

And so I changed the script so the fireflies appear only when it's dark.

There's a scripting command called llGetSunDirection. It gives you x, y, and z vectors for the position of the Second Life sun. The z component is positive when the sun is above the horizon, and negative when the sun is below the horizon. It would have been a simple matter to use zero as the trigger, but in real life fireflies begin flashing when it starts to grow dark (Sweetie pointed out they are active for an hour or two and then shut down for the rest of the night, but I chose to ignore that and leave them on all through the one-hour Second Life night).

I decided to turn the fireflies on at dusk and off at dawn-- but to do that I needed to know what the z position of the sun was when it was just dark enough to turn them on and just light enough to turn them off.

To do that, I needed to know the z position of the sun at those times.

I made a script that showed in hover text the z position, set it to update every ten seconds, and watched as the z position changed. I re-watched season one of The Killing for a couple of hours as the day progressed until the sun set, and managed to determine a z of  +.1 was was just about the right time to trigger the fireflies.

For the record, the z vector slowly increases from 0 to 1 as the day progresses, then slowly decreases to 0 as the sun goes below the horizon. It decreases to -.5 (I think; I could stay awake no longer and went to bed) and then begins to increase.

So anyway, I produced a new and improved Sweetie-tweaked Foxfire script and today replaced the script all over Whimsy. If you would like a copy of the script, I'll be happy to give you one (with full permission). Just IM me or send me a notecard.

No comments: