User:Toady Nakamura/Random Color

From Second Life Wiki
< User:Toady Nakamura
Revision as of 19:58, 11 March 2012 by Toady Nakamura (talk | contribs) (put up this simple randomizing script for beginning student's of LSL reference)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In SL, color is composed of three elements (Red, Green, Blue) in values from zero to 1.0; thus randomizing using llFrand(1.0) works well because the values to randomize within are from zero to 1.0

White is <1.0,1.0,1.0> and Black is <0.0,0.0,0.0> although you may see it as Black is <FALSE,FALSE,FALSE> because TRUE is 1 and FALSE is 0. LSL automatically accepts float numbers (with decimals) for integers and opposite. It's called "implicit typecasting."



<lsl> default {

   state_entry() 
   {
       llSetTimerEvent(2.0); // call a timer event every 2 seconds
   }
   timer() 
   {
       llSetColor(<llFrand(1.0),llFrand(1.0),llFrand(1.0)>, ALL_SIDES);
       //randomizes Red, Green & Blue independently & changes all sides of the prim.
   }

} </lsl>