Color and Texture Objects Via the SL Sun Cycles

From Lucinda Bulloch: You can copy and paste the parts you want or all of it it does work.

//i wrote this code as part of code to grow plants, it is used to make the plants face the sun and color them from a list of colors
//and adjust the food value of the plant but can easly be used for textures or all manner of thing like a sundial
//Modular script will be releasing the plant code later in the year - but i found this fun to write and would like to share it with you
//you can make the list as long as you like and they can all be of diff lengths - it uses float to calc the list pos so memory is the only limit

float nightdivider = -0.45; // this is the lowest level Z will fall to - sl has seasons so this changes - you can work out a function for these
float daydivider = 0.89;    // this is the highest level Z will reach - these dividers find the correct position in the texture list

integer lampoff = TRUE;

list morningcolors = ;
list afternooncolors = ;
list eveningcolors = ;
list nightcolors = ;

list morningtextures = ;
list afternoontextures = ;
list eveningtextures = ;
list nighttextures = ;

integer LINK_NUMBER = LINK_SET; //if for a linked prim put its number here
integer FACE = ALL_SIDES;       //if for a face put its number here

dotexture(list textures , integer sunposdiv)

//use the next line to test - things like the right texture names - comment out when done    
//this next line prints the texture to all faces
//this next line prints the texture to all faces of a linked prim
//this next line use setprimparams to print the texture to all faces
//this next line use setprimparams to print the texture to all faces of a linked prim


docolors(list textures , integer sunposdiv)

//for colors list with color vectors ie
//this prints to a linked prim


     //this gets the sun pos     
     vector sunpos = llGetSunDirection();
     //this bit sorts what color to use - colors can be used to tint - use this part for colors only
     if((sunpos.z < 0) && (sunpos.x < 0)) docolors(eveningcolors,llFloor((sunpos.z/nightdivider)*(float)llGetListLength(eveningcolors)));
     else if(sunpos.z < 0) docolors(nightcolors,llGetListLength(nightcolors)-llCeil((sunpos.z/nightdivider)*(float)llGetListLength(nightcolors)));
     else if(sunpos.x > 0) docolors(morningcolors,llFloor((sunpos.z/daydivider)*(float)llGetListLength(morningcolors)));
     else docolors(afternooncolors,llGetListLength(afternooncolors)-llCeil((sunpos.z/daydivider)*(float)llGetListLength(afternooncolors)));
     //this bit sorts what texture to use - use only this part for textures only
     if((sunpos.z < 0) && (sunpos.x < 0)) dotexture(eveningtextures,llFloor((sunpos.z/nightdivider)*(float)llGetListLength(eveningtextures)));
     else if(sunpos.z < 0) dotexture(nighttextures,llGetListLength(nighttextures)-llCeil((sunpos.z/nightdivider)*(float)llGetListLength(nighttextures)));
     else if(sunpos.x > 0) dotexture(morningtextures,llFloor((sunpos.z/daydivider)*(float)llGetListLength(morningtextures)));
     else dotexture(afternoontextures,llGetListLength(afternoontextures)-llCeil((sunpos.z/daydivider)*(float)llGetListLength(afternoontextures)));
     //if you wish to make it shine in the evening only - street lamp or a magic plant
     //format of the prim light =
     if((sunpos.z < 0) && (sunpos.x < 0) && (lampoff)){lampoff = FALSE; llSetPrimitiveParams();}
     else if((sunpos.z < 0) && (sunpos.x > 0) && (!lampoff)) {lampoff = TRUE;llSetPrimitiveParams();}


Flash Scratch to SL - Your Scripting Tool

Script ImageNeed to write a LSL script and don't know how to script?  I know I hate trying to get my head around LSLS when I an in a time crunch. So why not give Flash Scratch a try! Its a great tool for learning and scoding your own scripts for Second Life without having to pay someone to do it and without a crash course in LSL

A Huge thanks to John Bennet of ATLAS Institute at University of Colorado and Eric Rosenbaum at MIT for writing Scratch for SL to begin with.

Read more: Flash Scratch to SL - Your Scripting Tool