Probably yes, it is.
Post your code.
It is currently April 23rd, 2024, 12:37 pm
Gradient angle in relation to time
-
- Posts: 826
- Joined: November 20th, 2012, 11:58 pm
-
- Posts: 75
- Joined: August 5th, 2014, 2:09 am
Re: Gradient angle in relation to time
I'm not sure if anything has changed from above, but just in case, here you go! [and thanks in advance!]:FreeRaider wrote:Probably yes, it is.
Post your code.
Code: Select all
[Rainmeter]
AppVersion=10000
; BackgroundMode=2
; SolidColor=255,255,255,192
MouseOverAction = [!ShowMeter TimeCircle]
MouseLeaveAction = [!HideMeter TimeCircle]
Update=1000
[Metadata]
Name=Minecraft clock
Author=Fuzzy[Lizard]530
Description=Couldn't find anything like this, so I made my own.
Version=1.x.x
License=Whatever. Credit appreciated, not required.
[MeasureTime]
Measure=Time
DaylightSavingTime=1
[MeterHours]
MeasureName=MeasureTime
Meter=ROTATOR
ImageName=dial.png
X=56
Y=64
; W=104
; H=104
; SolidColor=0,0,64
; SolidColor2=64,128,255
StartAngle=0
RotationAngle=6.2832
ValueRemainder=86400
OffsetX=52
OffsetY=52
[MeterFront]
Meter=IMAGE
X=0
Y=0
ImageName=clock.png
[TimeCircle]
Meter=Roundline
MeasureName=MeasureTime
X=0
Y=0
W=112
H=112
StartAngle=4.712
RotationAngle=6.283
LineLength=56
LineWidth=3
LineStart=50
LineColor=255,0,0,255
Solid=1
AntiAlias=1
ValueRemainder=86400
Hidden=1
-
- Rainmeter Sage
- Posts: 16162
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Gradient angle in relation to time
I'm not sure I understand what you mean by
So, finally my question is what you mean by the above sentence?
but for sure I wouldn't pull the sunrise/sunset from a weather site. Instead I'd use a lua script to calculate them.FuzzyLizard530 wrote:to have the rotation adjusted, say, on a daily basis by the sunrise/sunset time
So, finally my question is what you mean by the above sentence?
-
- Posts: 75
- Joined: August 5th, 2014, 2:09 am
Re: Gradient angle in relation to time
Oi! I'm not sure I can wordify this! LOL!balala wrote:I'm not sure I understand what you mean by
but for sure I wouldn't pull the sunrise/sunset from a weather site. Instead I'd use a lua script to calculate them.
So, finally my question is what you mean by the above sentence?
What I'm thinking is to have the Lua script you're suggesting [That DOES sound like a better idea!] adjust it so the "sun" doesn't enter/leave the view hole until the respective times. So essentially, at sunrise, the first few pixels of "the sun are peeking into view, sunset, they're just leaving the other side. Then again, I might have to adjust the view hole to make it look good for this.
Maybe a better way to put it, think of it as a circle, with sunrise on the left, sunset on the right.
-
- Rainmeter Sage
- Posts: 16162
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Gradient angle in relation to time
Ok, let's start at the beginning: I'll show you how to add a proper lua script, which will calculate the sunrise / sunset.
So, first here is the lua code. save it as Sun.lua, into the @Resources folder:
Now add the following variables, to the [Variables] section of your skin:
Add here your geographical coordinates and the time zone. For the geographical latitude, use positive values for the northern hemisphere and negative values for the southern hemisphere. Same way for the longitude you have to use positive values for the eastern hemisphere and negative ones, for the western hemisphere. The time zone have to be positive or negative accordingly.
Also add the following Script measure:
The Sun.lua will calculate and return the moment of Sunrise and Sunset, as the TimeSR and TimeSS variables.
Now for first, let's add a string meter, to can check what the script returns:
If you set correctly the geographical latitude and longitude, respectively the time zone, on the upper left corner of your skin, you'll see the Sunrise and Sunset, in 24 hours format. Even if you're using the 12 hours format, leave it as it is now, because later will be easier to use them in this form.
Now, does the skin shows the proper moments correctly?
So, first here is the lua code. save it as Sun.lua, into the @Resources folder:
Code: Select all
-- Lua program calculating the sunrise and sunset for
-- a given date and location(latitude,longitude)
-- Note, twilight calculation gives insufficient accuracy of results
-- Elias Karakoulakis, 2010
-- adaptation from C code from
-- Jarmo Lammi 1999 - 2001
-- Last update July 21st, 2001
-- http://www.sci.fi/~benefon/stuff.html
function Initialize()
sin,cos,tan = math.sin, math.cos, math.tan
asin,acos,atan,atan2 = math.asin, math.acos, math.atan, math.atan2
pi = math.pi
degs=0
rads=0
L,g,daylen=0,0,0
SunDia = 0.53
-- Sunradius degrees
AirRefr = 34/60
-- athmospheric refraction degrees
_day=tonumber(os.date("%d", os.time()+3600*24))
_month=tonumber(os.date("%m", os.time()+3600*24))
_year=tonumber(os.date("%Y", os.time()+3600*24))
Old = _day
_timezone=getTimeOffset()/3600
_latitude = tonumber(SKIN:GetVariable('Latitude'))
_longitude = tonumber(SKIN:GetVariable('Longitude'))
_minsunicon = tonumber(SKIN:GetVariable('MinForSunIcon'))
if _minsunicon>120 then _minsunicon = 120 end
OldDay, OldMonth, OldYear = _day, _month, _year
rscalc({ day=_day, month=_month, year= _year } , {latit = _latitude, longit = _longitude, tzone = _timezone} )
end
function Update()
_day=tonumber(os.date("%d", os.time()+3600*24))
_month=tonumber(os.date("%m", os.time()+3600*24))
_year=tonumber(os.date("%Y", os.time()+3600*24))
_timezone=getTimeOffset()/3600
New = _day
if _day~=OldDay or _month~=OldMonth or _year~=OldYear then
rscalc({ day=_day, month=_month, year= _year } , {latit = _latitude, longit = _longitude, tzone = _timezone} )
OldDay, OldMonth, OldYear = _day, _month, _year
end
SKIN:Bang('!SetVariable', 'SunIc', SunRiseIcon(Hours(riset), Minutes(riset))+SunSetIcon(Hours(settm), Minutes(settm)))
if Old ~= New then
Old = New
end
end
-- Get the days to J2000
-- h is UT in decimal hours
-- FNday only works between 1901 to 2099 - see Meeus chapter 7
function FNday (y, m, d, h)
luku = - 7 * (y + (m + 9)/12)/4 + 275*m/9 + d
luku = luku + y*367
return luku - 730531.5 + h/24
end
-- the function below returns an angle in the range
-- 0 to 2*pi
function FNrange (x)
local b = 0.5*x / pi
local a = 2*pi * (b - math.floor(b))
if (a < 0) then a = 2*pi + a end
return a
end
-- Calculating the hourangle
function f0(lat, declin)
local fo,dfo
-- Correction: different sign at S HS
dfo = rads*(0.5*SunDia + AirRefr)
if (lat < 0) then dfo = -dfo end
fo = tan(declin + dfo) * tan(lat*rads)
if (fo>0.99999) then fo=1 end
-- to avoid overflow
fo = asin(fo) + pi/2
return fo
end
-- Calculating the hourangle for twilight times
function f1(lat, declin)
local fi,df1
-- Correction: different sign at S HS
df1 = rads * 6
if (lat < 0) then df1 = -df1 end
fi = tan(declin + df1) * tan(lat*rads)
if (fi>0.99999) then fi=1 end
-- to avoid overflow
fi = asin(fi) + pi/2
return fi
end
-- Find the ecliptic longitude of the Sun
function FNsun (d)
-- mean longitude of the Sun
L = FNrange(280.461 * rads + .9856474 * rads * d)
-- mean anomaly of the Sun
g = FNrange(357.528 * rads + .9856003 * rads * d)
-- Ecliptic longitude of the Sun
return FNrange(L + 1.915 * rads * sin(g) + .02 * rads * sin(2 * g))
end
function rscalc(when, where)
local y, m, d, h, latit, longit
local inlat, inlon, intz
local tzone, d2k, lambda
local obliq, alpha, delta, LL, equation, ha, hb, twx
local twam, altmax, noont, twpm
settm,riset=0,0
degs = 180/pi
rads = pi/180
h = 12
y,m,d = when.year, when.month, when.day
latit, longit, tzone = where.latit, where.longit, where.tzone
d2k = FNday(y, m, d, h)
-- Use FNsun to find the ecliptic longitude of the Sun
lambda = FNsun(d2k)
-- Obliquity of the ecliptic
obliq = 23.439 * rads - .0000004 * rads * d2k
-- Find the RA and DEC of the Sun
alpha = atan2(cos(obliq) * sin(lambda), cos(lambda))
delta = asin(sin(obliq) * sin(lambda))
-- Find the Equation of Time in minutes
-- Correction suggested by David Smith
LL = L - alpha
if (L < pi) then LL = LL + 2*pi end
equation = 1440 * (1 - LL / pi/2)
ha = f0(latit,delta)
hb = f1(latit,delta)
twx = hb - ha
-- length of twilight in radians
twx = 12*twx/pi
-- length of twilight in hours
-- Conversion of angle to hours and minutes //
daylen = degs*ha/7.5
if (daylen<0.0001) then daylen = 0 end
-- arctic winter //
riset = 12 - 12 * ha/pi + tzone - longit/15 + equation/60
settm = 12 + 12 * ha/pi + tzone - longit/15 + equation/60
noont = riset + 12 * ha/pi
altmax = 90 + delta * degs - latit
-- Correction for S HS suggested by David Smith
-- to express altitude as degrees from the N horizon
if (latit < delta * degs) then altmax = 180 - altmax end
twam = riset - twx
-- morning twilight begin
twpm = settm + twx
-- evening twilight end
if (riset > 24) then riset = riset-24 end
if (settm > 24) then settm = settm-24 end
if (Hours(riset) >= 0) and (Hours(settm) >= 0) then
SKIN:Bang('!SetVariable TimeSR "'..ToTime(Hours(riset),Minutes(riset))..'"')
else
SKIN:Bang('!SetVariable TimeSR "No rise"')
end
if (Hours(riset) >= 0) and (Hours(settm) >= 0) then
SKIN:Bang('!SetVariable TimeSS "'..ToTime(Hours(settm),Minutes(settm))..'"')
else
SKIN:Bang('!SetVariable TimeSS "No set"')
end
SKIN:Bang('!SetVariable TimeNoon "'..ToTime(Hours(noont),Minutes(noont))..'"')
if Minutes(daylen)>=60 then
SKIN:Bang('!SetVariable DayLength "'..(Hours(daylen)+1)..' H 0 M"')
else
if Minutes(daylen) < 10 then
SKIN:Bang('!SetVariable DayLength "'..Hours(daylen)..':0'..Minutes(daylen)..'"')
else
SKIN:Bang('!SetVariable DayLength "'..Hours(daylen)..':'..Minutes(daylen)..'"')
end
end
SKIN:Bang('!SetVariable MaxAltitude "'..string.format('%.2f',altmax)..'"')
SKIN:Bang('!SetVariable Declination "'..string.format('%.2f',(delta * degs))..'"')
end
function ToTime(HH,MM)
if tonumber(SKIN:GetVariable('12H'))>0 then --12H
if MM>=60 then
return AMPMFormat((HH+1),string.format('%02d','0'))
else
return AMPMFormat((HH),string.format('%02d',MM))
end
else -- 24H
if MM>=60 then
return tostring((HH+1)..':00')
else
return tostring(HH..':'..string.format('%02d',MM))
end
end
end
function AMPMFormat(HH,MM)
if tonumber(HH) <= 11 then
return(HH..':'..MM..' AM')
else
if tonumber(HH)==12 then
return(HH..':'..MM..' PM')
else -- then HH must be in interval [13-23]
return((tonumber(HH)-12)..':'..MM..' PM')
end
end
end
function Hours(DecimalNumber)
return math.floor(DecimalNumber)
end
function Minutes(DecimalNumber)
return Round(60*(DecimalNumber-math.floor(DecimalNumber)))
end
function Round(num)
if num >= 0 then
return math.floor(num+.5)
else
return math.ceil(num-.5)
end
end
function SunRiseIcon(HH, MM)
local Offset = (60*os.date("%H")+os.date("%M")-60*HH-MM)
local SRI
if Offset<-_minsunicon then
SRI = 3
else
if Offset<0 then
SRI = 2
else
if Offset<_minsunicon then
SRI = 1
else
SRI = 0
end
end
end
return SRI
end
function SunSetIcon(HH, MM)
local Offset = (60*os.date("%H")+os.date("%M")-60*HH-MM)
local SSI
if Offset<-_minsunicon then
SSI = 0
else
if Offset<0 then
SSI = 1
else
if Offset<_minsunicon then
SSI = 2
else
SSI = 3
end
end
end
return SSI
end
function getTimeOffset()
return (os.time() - os.time(os.date('!*t')) + (os.date('*t')['isdst'] and 3600 or 0))
end
Code: Select all
[Variables]
Latitude=ADD HERE THE GEOGRAPHICAL LATITUTE
Longitude=AND HERE THE LONGITUDE
12H=0
tZone=ADD HERE YOUR TIMEZONE
MinForSunIcon=20
Also add the following Script measure:
Code: Select all
[MeasureLuaScriptSun]
Measure=SCRIPT
ScriptFile=#@#Sun.lua
Now for first, let's add a string meter, to can check what the script returns:
Code: Select all
[SunRiseSet]
MeasureName=MeasureUptime
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=Sunrise: #TimeSR##CRLF#Sunset: #TimeSS#
DynamicVariables=1
Now, does the skin shows the proper moments correctly?
-
- Posts: 75
- Joined: August 5th, 2014, 2:09 am
Re: Gradient angle in relation to time
It matches what I have on another skin that downloads the info, if that's what you mean...balala wrote:If you set correctly the geographical latitude and longitude, respectively the time zone, on the upper left corner of your skin, you'll see the Sunrise and Sunset, in 24 hours format. Even if you're using the 12 hours format, leave it as it is now, because later will be easier to use them in this form.
Now, does the skin shows the proper moments correctly?
I'm just not sure what to do with that info. The math to adjust the rotation is beyond me...