Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

KDC's Opensource non linear solar clock

Kyrah Abattoir
cruelty delight
Join date: 4 Jun 2004
Posts: 2,786
02-15-2007 11:49
This is a bit of code i made to reflect the SL sun time, can be useful for roleplaying places that need clocks to display the proper time of the day according to the SL day/night cycle.

NOTE: the speed at which time flow is not linear, in SL we have 3 hours of daytime for 1 hour of night time, but my clock is designed to consider day/night to be of equal length, so during the night the clock time flow FASTER than during the daytime, of course if the sim where you put the clock has time forced to a specific hour, the clock will be frozen too.

CODE

// KDC's non linear solar clock
// Copyright (C) 2005 Kyrah Abattoir
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

string tod = "am";
integer hour = 3600;
integer minute = 60;
default
{
state_entry()
{
vector sun_angle =llGetSunDirection()*llEuler2Rot(<PI/4,0,0>);//flattening the vector
sun_angle.z = 0;//filtering z out

sun_angle = llVecNorm(sun_angle);//normalize

float angle = llAcos(sun_angle.y/1)*RAD_TO_DEG;//convert the coords of the sun to angle

if(sun_angle.x <0)//if we use the evening part of the quadrant
{
angle = 180 - angle;
tod = "pm";//switch to pm
}

float time = angle * 240;//convert in seconds
integer hours = (integer)(time/hour);//extract hours
time -= hour*hours;//substract seconds used by hours
string minutes = (string)((integer)(time/minute));//extract minutes

if( llStringLength(minutes) == 1 )//add a 0 to values of 1 digit
minutes = "0"+minutes;

llSetText((string)hours+":"+minutes+tod,<1,1,1>,1.0);
llSleep(10.0);//sun is updated every 10 seconds
llResetScript();
}
}
_____________________

tired of XStreetSL? try those!
apez http://tinyurl.com/yfm9d5b
metalife http://tinyurl.com/yzm3yvw
metaverse exchange http://tinyurl.com/yzh7j4a
slapt http://tinyurl.com/yfqah9u
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
02-16-2007 10:43
/54/da/166583/1.html
_____________________
i've got nothing. ;)