3 REFLEXIVE ARCHITECTURE SCRIPTS



// Reflexive Architecture Script 1: Change Size and Color per Avatar Distance

// For Keystone Bouchard. http://www.archsl.wordpress.com for an installation on Architecture Island, September 2007. Scripted by Fumon Kubo

//Shared under Creative Commons Attribution-Share Alike 3.0 License

vector NEAR_COL = <1.0, 1.0, 0.0>;
vector FAR_COL = <1.0, 0.5, 0.0>;

vector NEAR_SIZE = <1.0, 0.2, 1.0>;
vector FAR_SIZE = <0.2, 2.0, 0.5>;


float NEAR = 1.0;
float FAR = 5.0;

default
{
    state_entry()
    {
        llSay(0, "Hello, Avatar!");
        llSensorRepeat("", NULL_KEY, AGENT, FAR, PI, 0.2);
    }

    sensor(integer total_number)
    {
        float distance = llVecMag(llDetectedPos(0) - llGetPos());
        float scale = (distance - NEAR) / (FAR - NEAR);
        if (scale < 0.0) scale = 0.0;
        llSetScale(NEAR_SIZE + ((FAR_SIZE - NEAR_SIZE) * scale));
        llSetColor(NEAR_COL + ((FAR_COL - NEAR_COL) * scale), ALL_SIDES);
    }
}


// Reflexive Architecture Script 2: Change Opacity per Avatar Distance

// For Keystone Bouchard. http://www.archsl.wordpress.com for an installation on Architecture Island, September 2007. Scripted by Fumon Kubo</span>

//Shared under Creative Commons Attribution-Share Alike 3.0 License


//Settings

//~Distance from object to activate in metres.
    float distance = 10.5;
//~Timer length after somone leaves.
    float time = 0.5;
//~Timeperiod to fade in (seconds).
    float fadeTime = 0.5;
//~If True, this varriable multiplys time to be hours instead of seconds.
    integer Multiply_To_Hours = FALSE;
//~Side (-1 for all sides)
    integer side = -1;
   
fadeIn(){
    integer i;
    integer t = llCeil(fadeTime/0.1);
    for(i = 0; i<t; i++){
        llSetAlpha((i*0.1)/fadeTime, side);
        llSleep(0.1);
    }
}
//Globals DO NOT MODIFY.
integer active = FALSE;
integer active2 = FALSE;
integer noOne = FALSE;

default{
    state_entry(){
        llSetTimerEvent(0.0);
        if(Multiply_To_Hours){
            time = (time * 3600);
        }
        llSetAlpha(0.0, side);
        llSensorRemove();
        llSensorRepeat("", NULL_KEY, AGENT, distance, PI, 2.0);
    }
    sensor(integer ds){
        if(!active2){
            llSetTimerEvent(0.0);
            fadeIn();
            llSetAlpha(0.6, side);
            active2 = TRUE;
            noOne = FALSE;
        }
    }
    no_sensor(){
        if(!noOne){
            llResetTime();
            llSetTimerEvent(0.1);
            active2 = FALSE;
            noOne = TRUE;
        }
    }
    timer(){
        float timeT = llGetTime();
        if(timeT < time){
            llSetAlpha(1.0 - (timeT/time), side);
        }
        else{
            llSetAlpha(0.0, side);
            llSetTimerEvent(0.0);
        }
       
    }
}



// Reflexive Architecture Script 3: Prim Moves X-Meters from Avatar, Returns Home X-Seconds after Avatar Leaves

// <span style=”display: inline”>For Keystone Bouchard. http://www.archsl.wordpress.com for an installation on Architecture Island, September 2007. Scripted by Fumon Kubo</span>

//Shared under Creative Commons Attribution-Share Alike 3.0 License


//Settings
//~Range in metres.
    float range = 5.0;
//~Time in seconds for up tick.
    float time = 0.1;
//~Time in seconds for down tick.
    float downTime = 1.0;
//~Direction and distance (offset from origin when sense).
    vector direction = <0.1,0.0,0.1>;
//~Local (TRUE or FALSE)
    integer local = FALSE;
//Don't change bast here.
integer currentNum;
integer numMoves;

default {
    state_entry() {
        currentNum = 0;
        numMoves = 0;
        llSensorRepeat("", NULL_KEY, AGENT, range, PI, 0.25);
    }
    on_rez(integer ds){
        currentNum = 0;
        numMoves = 0;
    }
    sensor(integer num){
        if(!currentNum){
            currentNum = num;
            llSetTimerEvent(time);
        }
    }
    no_sensor(){
        if(currentNum){
            currentNum = FALSE;
            llSetTimerEvent(downTime);
        }
    }
    timer(){
        if(currentNum){
            if(local){
                llSetPos(llGetPos() + (direction * llGetRot()));
            }
            else{
                llSetPos(llGetPos() + direction);
            }
            numMoves++;
        }
        else if(numMoves > 0){
            if(local){
                llSetPos(llGetPos() - (direction * llGetRot()));
            }
            else{
                llSetPos(llGetPos() - direction);
            }
            numMoves = numMoves - 1;
        }
        else if(numMoves == 0){
            llSetTimerEvent(0.0);
        }
    }
}