2016-06-27

Light Ribbon/Glow Sticks

While sorting my outfit for last Saturday's Raven Park dance I had the sudden urge to make a pair of glow sticks, or something similar. I didn't really need anything clever, and for some odd reason I've yet to actually play with ribbon particles (I can see a few uses for products I make but it's just never happened for a few reasons) so this seemed like a good time.


A bit of coding later and I had something that worked well enough. It's not as fancy as it could be, and with Mistress' input on how things looked I made it so it was fairly subtle (for example, greater particle age makes for a more impressive effect but it also ends up hiding your avatar depending on the dance), but I'm pleased with the result.

On the off-chance that it's useful to someone else, here's the script:

//////////////////////////////////////////////////////////////////////
// Z&A Light Ribbon
// By Antony Fairport
//
// Z&A Light Ribbon - Quick and simple glowstick/ribbon
//
// Revision history:
// ------------------------------------------------------------
//
// 2016-06-25
// Initial revision.
//////////////////////////////////////////////////////////////////////
// Make the ribbon
MakeRibbon( vector vStartColour, vector vEndColour )
{
// Get the size of the stick, so we can adjust the particle.
vector vStickSize = llGetScale();
llParticleSystem( [
PSYS_PART_FLAGS, PSYS_PART_RIBBON_MASK |
PSYS_PART_INTERP_COLOR_MASK |
PSYS_PART_EMISSIVE_MASK,
PSYS_PART_MAX_AGE, 0.75,
PSYS_SRC_TEXTURE, TEXTURE_BLANK,
PSYS_PART_START_SCALE, < vStickSize.z, 0.02, 0.0 >,
PSYS_PART_START_ALPHA, 0.5,
PSYS_PART_END_ALPHA, 0.0,
PSYS_PART_START_GLOW, 0.2,
PSYS_PART_END_GLOW, 0.05,
PSYS_PART_START_COLOR, vStartColour,
PSYS_PART_END_COLOR, vEndColour
] );
}
//////////////////////////////////////////////////////////////////////
// Refresh the ribbon, loading colours from object desc.
RefreshRibbon()
{
// Get the description as a list.
list lColours = llParseString2List( llGetObjectDesc(), [ "~" ], [] );
// The start and end colours.
vector vStart = < 1.0, 0.0, 0.0 >;
vector vEnd = < 0.01, 0.0, 0.0 >;
// If we seem to have got enough stuff from the description...
if ( llGetListLength( lColours ) > 1 )
{
// ...assume we're getting colours.
vStart = (vector) llList2String( lColours, 0 );
vEnd = (vector) llList2String( lColours, 1 );
}
// Texture the stick itself.
llSetLinkPrimitiveParamsFast( LINK_THIS, [
PRIM_GLOW, ALL_SIDES, 0.2,
PRIM_FULLBRIGHT, ALL_SIDES, TRUE,
PRIM_COLOR, ALL_SIDES, vStart, 1.0
] );
// Make the ribbon.
MakeRibbon( vStart, vEnd );
}
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Restrict memory. We don't need much.
llSetMemoryLimit( 12 * 1024 );
// Get the ribbon off.
RefreshRibbon();
}
//////////////////////////////////////////////////////////////////
// When rezzed...
on_rez( integer _ )
{
RefreshRibbon();
}
//////////////////////////////////////////////////////////////////
// Handle being atached.
attach( key id )
{
if ( id )
{
RefreshRibbon();
}
}
//////////////////////////////////////////////////////////////////
// Handle changes.
changed( integer change )
{
// If the owner has changed...
if ( change & CHANGED_OWNER )
{
// ...reset the script.
llResetScript();
}
// If the size of the stick changed...
else if ( change & CHANGED_SCALE )
{
// ...refresh the particles.
RefreshRibbon();
}
}
}
To use it just make yourself a cylinder that's sized to your taste, drop the script in, attach it to your hand and you're good to go. The start and end colours (so how the light starts, and what it fades to) can be set by putting two colour vectors, separated by a ~, in the description of the object. For example, a description like this:

    < 1.0, 0.0, 0.0 >~< 0.0, 0.0, 0.0 >

will have the colour start at bright red and fade to black. The fade likely won't be very noticeable because it also fades to invisible (you can change that by tweaking the PSYS_PART_END_ALPHA value in the script, of course).

Hopefully this is of use to someone. :)

2 comments:

  1. Very cool. I noticed those at the dance but didn't realise you had made them. I like the level of light, not too much :)

    ReplyDelete
    Replies
    1. Sort of happened as a last-minute idea and then RL intruded -- my plan was to make a dispenser for them to put out at the set, or hand them out or something.

      Still, code's here for anyone to play with now. :)

      Delete