Dernière mise à jour : 08/09/2017 à 18h48
Table des matières
Position du soleil et de la lune
conkyrc
Code TEXT :
background no use_xft yes xftfont URW Chancery L:style=Bold:size=10 xftalpha 1 update_interval 1 total_run_times 0 own_window yes own_window_transparent yes own_window_argb_visual yes own_window_type normal own_window_hints undecorated,below,skip_taskbar,skip_pager double_buffer yes minimum_size 380 310 maximum_width 380 text_buffer_size 2048 draw_shades no draw_outline no draw_borders no border_width 1 draw_graph_borders no default_outline_color cacaca alignment top_right gap_x 5 gap_y 100 no_buffers yes uppercase no cpu_avg_samples 2 override_utf8_locale yes # color1 ffff00 lua_load ~/.conky/v11/conky/soleil.lua lua_draw_hook_pre draw_fig default_color 8b8b8b lua_load ~/.conky/lua/image.lua TEXT ${lua fDrawImage /home/loutch/.conky/v11/conky/terre.png 170 170 60 64 0}
soleil.lua
Code TEXT :
--sun position lua script by mrpeachy 2010 version 2 includes moon position --############################################################ --############################################################ --input latitude --for northern hemisphere enter positive --for southern hemisphere enter negative latitude=-49.1 longitude=7.06 --input hemisphere --for northern enter 1 --for southern enter 2 hemisphere=2 --daylight saving? 1=yes, 0=no dst=0 --position - this is the point where the N-S line crosses the horizon line --the .5 helps make lines look sharper across=200.5 down=200.5 --############################################################ --############################################################ require 'cairo' function cos(x) a=math.cos(math.rad(x)) return a end function sin(x) a=math.sin(math.rad(x)) return a end function tan(x) a=math.tan(math.rad(x)) return a end function addzero10(num) if tonumber(num) < 10 then return "0" .. num else return num end end function round(val, decimal) if (decimal) then return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) else return math.floor(val+0.5) end end function string:split(delimiter) local result = { } local from = 1 local delim_from, delim_to = string.find( self, delimiter, from ) while delim_from do table.insert( result, string.sub( self, from , delim_from-1 ) ) from = delim_to + 1 delim_from, delim_to = string.find( self, delimiter, from ) end table.insert( result, string.sub( self, from ) ) return result end function datan2(y, x) if x == 0 and y == 0 then return 0 else a = math.atan(math.rad(y / x)) end if (x < 0) then a = a + 180 else if y < 0 and x > 0 then a = a + 360 end end return math.rad(a) end function ipart(x) if (x> 0) then a = math.floor(x) else a = math.ceil(x); end return a end function range(x) b = x / 360; a = 360 * (b - ipart(b)); if a < 0 then a = a + 360 end return a end function ranget(x) b = x / 24; a = 24 * (b - ipart(b)); if a < 0 then a = a + 24 end return a end function rangei(x) b = x / 1440; a = 1440 * (b - ipart(b)); if a < 0 then a = a + 1440 end return a end --################################################################################################################################################ --########### MAIN FUNCTION ######################################################################################################## --################################################################################################################################################ --################################################################################################################################################ function conky_draw_fig() if conky_window == nil then return end local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height) cr = cairo_create(cs) local updates=tonumber(conky_parse('${updates}')) --########### START FUNCTION ######################################################################################################## if updates > 5 then --########### SET HEMISPHERE ######################################################################################################## if hemisphere==1 then start=0 else start=180 end --################ sets daylignt saving #####################################3 if dst==1 then ds=-1 else ds=0 end --################################################################################################################################################ --################################################################################################################################################ --########### calculate julian time ######################################################################################################## --################################################################################################################################################ --################################################################################################################################################ M=os.date("%m") --month K=os.date("%G") --4 digit year I=(os.date("%d"))--day of month H=ranget((os.date("%H"))+ds) --hours Min=os.date("%M") Mi=(os.date("%M"))/60 --minutes expressed as hours --current Julian time----------------------------------------------------------------- JD=round((367*K)-((7*(K+((M+9)/12)))/4)+((275*M)/9)+I+1721013.5,0)+0.5+((H+Mi)/24) -------------------------------------------------------------------------------------- days=(JD)-2451545.0 --correct T=days/36525 --correct --Julian time at preceeding midnight JD0=round((367*K)-((7*(K+((M+9)/12)))/4)+((275*M)/9)+I+1721013.5,0)+0.5 D0=JD0-2451545.0 --########### calculate sidereal time ######################################################################################################## --current sidereal time CST=6.697374558+(0.06570982441908*D0)+(1.00273790935*(H+Mi)) ----------------------------------------------------------------- GMST = 6.697374558 + (0.06570982441908*D0) + (1.00273790935*(H+Mi)) + (0.000026*(T^2)) ADJ=longitude/15 GMST24=ranget(GMST) GMST24S=string.split(GMST24, "%p") GMST24H=GMST24S[1] GMST24M=string.len(GMST24S[2]) GMST24M=GMST24S[2]/(10^(GMST24M))*60 GMST24M=string.split(GMST24M,"%p") GMST24M=GMST24M[1] sgtime=(GMST24H*60)+GMST24M ------------------------------------------------------------- day=os.date("%j") B=(360/365)*(day-81) eot=(9.87*math.sin(2*B))-(7.53*math.cos(B))-(1.5*math.sin(B)) LSTM=15*10 TC=(4*(LSTM-longitude))+eot LT=((H)*60)+Min LST=LT+(TC/60) --------------------------------------- LST24=ranget(LST/60) LST24S=string.split(LST24, "%p") LST24H=LST24S[1] LST24M=string.len(LST24S[2]) LST24M=(LST24S[2]/(10^(LST24M)))*60 LST24M=string.split(LST24M,"%p") LST24M=LST24M[1] --below is current solar time stime=(LST24H*60)+LST24M --################################################################################################################################################ --############# END TIME CALCS ########################################################################################################### --################################################################################################################################################ --################################################################################################################################################ --############# SUN CACULATIONS AND DISPLAY ########################################################################################################### --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ -- Sun formulas -- -- L1 - Mean longitude -- M1 - Mean anomaly -- C1 - Equation of centre -- V1 - True anomaly -- Ec1 - Eccentricity -- R1 - Sun distance -- Th1 - Theta (true longitude) -- Om1 - Long Asc Node (Omega) -- Lam1- Lambda (apparent longitude) -- Obl - Obliquity of ecliptic -- Ra1 - Right Ascension -- Dec1- Declination t=T L1 = range(280.466 + 36000.8 * t) M1 = range(357.529+35999*t - 0.0001536* t*t + t*t*t/24490000) sinm1=math.sin(math.rad(M1)) C1 = (1.915 - 0.004817* t - 0.000014* t * t)* sinm1; C1 = C1 + (0.01999 - 0.000101 * t)* sinm1; C1 = C1 + 0.00029 * sinm1; V1 = M1 + C1; cosv1=math.cos(math.rad(V1)) Ec1 = 0.01671 - 0.00004204 * t - 0.0000001236 * t*t; R1 = 0.99972 / (1 + Ec1 * cosv1);--correct Th1 = L1 + C1 Om1 = range(125.04 - 1934.1 * t) om1sin=math.sin(math.rad(Om1)) Lam1 = Th1 - 0.00569 - 0.00478 * math.deg(om1sin); Obl = (84381.448 - 46.815 * t)/3600; --correct th1sin=math.sin(math.rad(Th1)) th1cos=math.cos(math.rad(Th1)) th1tan=math.tan(math.rad(Th1)) oblsin=math.sin(math.rad(Obl)) oblcos=math.cos(math.rad(Obl)) obltan=math.tan(math.rad(Obl)) zsin=math.sin(math.rad(0)) zcos=math.cos(math.rad(0)) ztan=math.tan(math.rad(0)) Ra1 = datan2((th1sin * oblcos - ztan* zsin),th1cos)--close ish Dec1 = math.asin(zsin* oblcos + zcos*oblsin*th1sin)--very close --SUN CALCULATIONS--------------------------------------------------------------- ------------------------------------------------------- delta=math.deg(Dec1) ------------------------------------------------------ sdec=delta --calculate hangle in relation to altitude in relation to time althrtab={} shartab={} total=1440 for i=1,total do sha=180+(i*(360/total)) cossha=math.cos(math.rad(sha)) cossundec=math.cos(math.rad(sdec)) coslat=math.cos(math.rad(latitude)) cosmath=cossha*cossundec*coslat sinsundec=math.sin(math.rad(sdec)) sinlat=math.sin(math.rad(latitude)) sinmath=sinsundec*sinlat sinelevation=cosmath+sinmath elevation=math.deg(math.asin(sinelevation)) curaltlong=elevation curalt=round(curaltlong,2) althrtab[i]=curalt shartab[i]=sha-360 end --############################################# --calculate sunrise and sunset for i=1,(total-1) do if althrtab[i]<0 and althrtab[i+1]>0 then rise=i end if althrtab[i]>0 and althrtab[i+1]<0 then set=i end end rise=rise/60 rises=string.split(rise,"%p") sriseh=rises[1] riseml=string.len(rises[2]) risem=(rises[2]/(10^riseml))*60 risems=string.split(risem,"%p") srisem=risems[1] set=set/60 sets=string.split(set,"%p") sseth=sets[1] setml=string.len(sets[2]) setm=(sets[2]/(10^setml))*60 setms=string.split(setm,"%p") ssetm=setms[1] --############################################# --calculate azimuth for all above points if hemisphere==1 then azitab={} for i=1,total do azmath1=(math.cos(math.rad(shartab[i]))*cossundec*sinlat)-(sinsundec*coslat) azmath2=math.cos(math.rad(althrtab[i])) cosaz=azmath1/azmath2 azi1=math.deg(math.acos(cosaz)) aziplot=azi1 if shartab[i]<0 then azitab[i]=(aziplot-180)*-1 else azitab[i]=aziplot+180 end end end--if hemishpere if hemisphere==2 then azitab={} for i=1,total do azmath1=(math.cos(math.rad(shartab[i]))*cossundec*sinlat)-(sinsundec*coslat) azmath2=math.cos(math.rad(althrtab[i])) cosaz=azmath1/azmath2 azi1=math.deg(math.acos(cosaz)) aziplot=azi1 if shartab[i]<0 then azitab[i]=(aziplot-360)*-1 else azitab[i]=aziplot--+180 end end end--if hemishpere ------------------------------------------------------------------------------ --diplay sun plot for i = 1,total do circrad=0.25 circx=across-180+azitab[i] circy=down-althrtab[i] cairo_arc(cr,circx,circy,circrad,0,2*math.pi) cairo_close_path(cr) cairo_set_source_rgba(cr,0.4,0.4,0.4,1) cairo_fill (cr) end --plot current sun position circrad=7 circx=across-180+azitab[stime] circy=down-althrtab[stime] cairo_arc(cr,circx,circy,circrad,0,2*math.pi) cairo_close_path(cr) cairo_set_source_rgba(cr,1,1,0,1) cairo_fill (cr) ------------------------------- --curerent sun alt and azi sunalt=althrtab[stime] sunazi=azitab[stime] -------------------------------------------- --############################################################################ --draw vertical N-S line cairo_set_line_width (cr, 1) cairo_set_source_rgba(cr,0.5,0.5,0.5,1) cairo_move_to (cr, across, down+100) cairo_line_to (cr, across, down-100) cairo_stroke (cr) --draw horizon cairo_move_to (cr, across-180, down) cairo_line_to (cr, across+180, down) cairo_stroke (cr) if hemisphere==1 then cairo_move_to (cr, across-4, down-102) cairo_show_text (cr, "S") cairo_move_to (cr, across-4, down+109) cairo_show_text (cr, "N") else cairo_move_to (cr, across-4, down-102) cairo_show_text (cr, "N") cairo_move_to (cr, across-4, down+109) cairo_show_text (cr, "S") cairo_stroke (cr) end --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ --############# MOON CACULATIONS AND DISPLAY ########################################################################################################### --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ --calculate moon data---------------------------------------------------------------- --moon stuff F = range(93.2721 + 483202 * t - 0.003403 * t* t - t * t * t/3526000); L2 = range(218.316 + 481268 * t); Om2 = range(125.045 - 1934.14 * t + 0.002071 * t * t + t * t * t/450000); M2 = range(134.963 + 477199 * t + 0.008997 * t * t + t * t * t/69700); cosm2=math.cos(math.rad(M2)) D = range(297.85 + 445267 * t - 0.00163 * t * t + t * t * t/545900); D2 = 2*D; cosd2m2=math.cos(math.rad(D2-M2)) cosd2=math.cos(math.rad(D2)) R2 = 1 + (-20954 * cosm2 - 3699 * cosd2m2 - 2956 * cosd2 / 385000); R3 = (R2 / R1) / 379.168831168831; sinf=math.sin(math.rad(F)) sinm2f=math.sin(math.rad(M2-F)) sind2f=math.sin(math.rad(D2-F)) Bm = 5.128 * sinf + 0.2806 * sinm2f; Bm = Bm + 0.2777 * sinm2f + 0.1732 * sind2f; sinm2=math.sin(math.rad(M2)) sind2m2=math.sin(math.rad(D2-M2)) sind2=math.sin(math.rad(D2)) Lm = 6.289 * sinm2 + 1.274 * sind2m2 + 0.6583 * sind2; sin2m2=math.sin(math.rad(2*M2)) sin2f=math.sin(math.rad(2*F)) Lm = Lm + 0.2136 * sin2m2 - 0.1851 * sinm1 - 0.1143 * sin2f; sind22m2=math.sin(math.rad(D2-(2*M2))) Lm = Lm +0.0588 * sind22m2 sind2m1m2=math.sin(math.rad(D2-M1-M2)) sind2m22=math.sin(math.rad(D2+M2)) Lm = Lm + 0.0572* sind2m1m2 + 0.0533* sind2m22; Lm = Lm + L2; tanbm=math.tan(math.rad(Bm)) sinbm=math.sin(math.rad(Bm)) cosbm=math.cos(math.rad(Bm)) sinlm=math.sin(math.rad(Lm)) coslm=math.cos(math.rad(Lm)) Ra2 = math.atan((sinlm * oblcos - tanbm* oblsin)); Dec2 = math.asin(sinbm* oblcos + cosbm*oblsin*sinlm); sinlam1lm=math.sin(math.rad(Lam1-Lm)) HLm = range(Lam1 + 180 + (180/math.pi) * R3 * cosbm * sinlam1lm); HBm = R3 * Bm; -------------------------------------------------------------------- --obliquity of ecliptic: eps = 23.0 + 26.0/60.0 + 21.448/3600.0 - (46.8150*T+ 0.00059*T*T- 0.001813*T*T*T)/3600; X = cos(Bm)*cos(Lm) Y = cos(eps)*cos(Bm)*sin(Lm) - sin(eps)*sin(Bm) Z = sin(eps)*cos(Bm)*sin(Lm) - cos(eps)*sin(Bm) R = math.sqrt(1.0-Z*Z); delta = (180/math.pi)*math.atan(Z/R); -- in degrees-- declination RA = (24/math.pi)*math.atan(Y/(X+R)); -- in hours ------------------------------------------------------- delta=math.deg(Dec2) ------------------------------------------------------ sdec=delta althrtab={} shartab={} total=1440 cossundec=math.cos(math.rad(sdec)) coslat=math.cos(math.rad(latitude)) sinlat=math.sin(math.rad(latitude)) sinsundec=math.sin(math.rad(sdec)) sinmath=sinsundec*sinlat for i=0,total do sha=180+(i*(360/total)) cossha=math.cos(math.rad(sha)) cosmath=cossha*cossundec*coslat sinelevation=cosmath+sinmath elevation=math.deg(math.asin(sinelevation)) curaltlong=elevation curalt=round(curaltlong,2) althrtab[i]=curalt shartab[i]=sha-360 end --############################################# --calculate moonrise and moonset for i=1,(total-1) do if althrtab[i]<0 and althrtab[i+1]>0 then rise=i end if althrtab[i]>0 and althrtab[i+1]<0 then set=i end end rise=rise/60 rises=string.split(rise,"%p") mriseh=rises[1] riseml=string.len(rises[2]) risem=(rises[2]/(10^riseml))*60 risems=string.split(risem,"%p") mrisem=risems[1] set=set/60 sets=string.split(set,"%p") mseth=sets[1] setml=string.len(sets[2]) setm=(sets[2]/(10^setml))*60 setms=string.split(setm,"%p") msetm=setms[1] --############################################# --calculate azimuth for all above points if hemisphere==1 then azitab={} for i=1,total do azmath1=(math.cos(math.rad(shartab[i]))*cossundec*sinlat)-(sinsundec*coslat) azmath2=math.cos(math.rad(althrtab[i])) cosaz=azmath1/azmath2 azi1=math.deg(math.acos(cosaz)) aziplot=azi1 if shartab[i]<0 then azitab[i]=(aziplot-180)*-1 else azitab[i]=aziplot+180 end end end--if hemishpere if hemisphere==2 then azitab={} for i=1,total do azmath1=(math.cos(math.rad(shartab[i]))*cossundec*sinlat)-(sinsundec*coslat) azmath2=math.cos(math.rad(althrtab[i])) cosaz=azmath1/azmath2 azi1=math.deg(math.acos(cosaz)) aziplot=azi1 if shartab[i]<0 then azitab[i]=(aziplot-360)*-1 else azitab[i]=aziplot end end end--if hemishpere ------------------------------------------------------------------------------ --diplay moon plot for i = 1,total do circrad=0.25 circx=across-180+azitab[i] circy=down-althrtab[i] cairo_arc(cr,circx,circy,circrad,0,2*math.pi) cairo_close_path(cr) cairo_set_source_rgba(cr,0.7,0.7,0.7,1) cairo_fill (cr) end --plot current moon position madj=tostring(rangei(sgtime+360)) mtime=madj circrad=5 circx=across-180+(azitab[tonumber(mtime)]) circy=down-(althrtab[tonumber(mtime)]) cairo_arc(cr,circx,circy,circrad,0,2*math.pi) cairo_close_path(cr) cairo_set_source_rgba(cr,1,1,1,1) cairo_fill (cr) ------------------------------- --curerent moon alt and azi moonalt=althrtab[tonumber(mtime)] moonazi=azitab[tonumber(mtime)] --------------------------------------------- --################################################################################################################################################ --################################################################################################################################################ --############# TEXT DISPLAYS ########################################################################################################### --################################################################################################################################################ --################################################################################################################################################ --################################################################################################################################################ --draws text label font="Mono" fontsize=10 cairo_select_font_face (cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, fontsize); cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 0.5); --top left - sun moon alt and azi tlx=20 tly=20 adj=10 cairo_move_to (cr, tlx, tly) cairo_show_text (cr, "Positions") gap=10 add=fontsize+((fontsize/100)*adj)+gap cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Soleil") add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Azimut " .. round(sunazi,2) .. "°") add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Altitude " .. sunalt .. "°") gap=10 add=fontsize+((fontsize/100)*adj)+add+gap cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Lune") add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Azimut " .. round(moonazi,2) .. "°") add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Altitude " .. moonalt .. "°") tlx=180 tly=20 adj=10 cairo_move_to (cr, tlx, tly) cairo_show_text (cr, "Heure") gap=10 add=fontsize+((fontsize/100)*adj)+gap cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Heure Locale: " .. H .. ":" .. Min) add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Heure Sidérale: " .. GMST24H .. ":" .. GMST24M ) add=fontsize+((fontsize/100)*adj)+add cairo_move_to (cr, tlx, tly+add) cairo_show_text (cr, "Heure Solaire : " .. LST24H .. ":" .. LST24M) cairo_stroke (cr) --####################################################################### --########################################################################################### --########################################################################################### --########################################################################################### --########################################################################################### end-- end if updates = end--end main function