Edie_Shoreland

Random Color function

Apr 11th, 2019
1,579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float seed = 5.0; //allows R, G or B to dominate
  2.  
  3. //Lower seeds even out RGB values and produce more
  4. //desaturated colors. For less saturation keep your
  5. //combined brightener + seed value below 10.0 and try
  6. //experimenting with seed values less than 1.0
  7.  
  8. float brightener = 5.0; //pushes up luminance value
  9. //Try to keep values for brightener + seed <= 10.0
  10. //A negative brightener (with a seed of 10.0) produces
  11. //darker colors.
  12.  
  13. string base_texture = "5748decc-f629-461c-9a36-a35a221fe21f";
  14. //replace the UUID with the name or key of the object's
  15. //base texture. The base texture should be a light de-
  16. //saturated texture like a shadow map. If you have a
  17. //detailed "white" version of the texture, even better!
  18.  
  19.  
  20. vector RandomColor(float hiValue, float lighten)
  21. {
  22.     //The RandomColor function prevents muddy colors you'd
  23.     //get from completely randomizing the R, G, and B values
  24.     //separately.
  25.  
  26.     //RandomColor allows one color to dominate by giving it
  27.     //the full "seed" value and splits the "seed" value bet-
  28.     //ween the other two colors. You still end up with more
  29.     //"greenish" colors, but at least they're a bit more
  30.     //vibrant than the purple and mustard browns you get with
  31.     //R, G, and B being purely random.
  32.  
  33.     hiValue = hiValue/10;
  34.     lighten = lighten/10;
  35.     float x = hiValue; //One lucky color will get the full seed value
  36.     float y = llFrand(hiValue); //The next gets a random portion of it
  37.     float z = hiValue - y; //The last gets the remaining portion.
  38.     list colorMix = [x + lighten, y + lighten, z + lighten];
  39.     list cRND = llListRandomize(colorMix,1);
  40.     vector nuColor= <llList2Float(cRND,0),llList2Float(cRND,1),llList2Float(cRND,2)>;
  41.     return nuColor;
  42. }
  43.  
  44. default
  45. {
  46.     state_entry()
  47.     {
  48.         llSetTexture(base_texture,ALL_SIDES );
  49.         //...or just the side you need it on.
  50.     }
  51.  
  52.     on_rez(integer start_param)
  53.     {
  54.         llSetColor(RandomColor(seed, brightener), ALL_SIDES);
  55.         //llSetTimerEvent(14400); //Change color every SL day cycle.
  56.     }
  57.  
  58.     touch_start(integer total_number)
  59.     {
  60.         llSetColor(RandomColor(seed, brightener), ALL_SIDES);
  61.     }
  62.  
  63.     timer()
  64.     {
  65.         llSetColor(RandomColor(seed, brightener), ALL_SIDES);
  66.     }
  67. }
Advertisement