Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function init() {
- today= new Date()
- ID=today.getDate()
- IM=today.getMonth()+1
- IY=today.getYear()+1900
- B5=54.58
- L5=52.14
- H=-3
- P1=3.14159265
- P2=2.*P1
- DR=P1/180.
- document.suncalc.ID.value=ID
- document.suncalc.IM.value=IM
- document.suncalc.IY.value=IY
- document.suncalc.B5.value=B5
- document.suncalc.L5.value=L5
- document.suncalc.H.value=H
- document.suncalc.SR.value=""
- document.suncalc.SS.value=""
- }
- function myint(x){
- if (x>=0)
- x=Math.floor(x)
- else
- x=Math.ceil(x)
- return x
- }
- function sunrise(form) {
- with (Math){
- ID=parseInt(form.ID.value)
- IM=parseInt(form.IM.value)
- IY=parseInt(form.IY.value)
- B5=parseFloat(form.B5.value)
- L5=parseFloat(form.L5.value)
- H =parseInt(form.H.value)
- form.SR.value=""
- form.SS.value=""
- L5=L5/360.
- Z0=H/24.
- G=1
- J3=0
- if (IY<1583){
- G=0
- }
- with(Math){
- D1=myint(ID)
- F=ID-D1-.5
- J=-myint(7*(myint((IM+9)/12)+IY)/4)
- if (G != 0) {
- S=((IM-9)<0?-1:1)
- A=abs(IM-9)
- J3=myint(IY+S*myint(A/7))
- J3=-myint((myint(J3/100)+1)*3/4)
- }
- J=J+myint(275*IM/9)+D1+G*J3
- J=J+1721027+2*G+367*IY
- if (F<0) {
- F=F+1
- J=J-1
- }
- }
- T=(J-2451545.)+F
- TT=T/36525.+1.
- T0=T/36525.
- S=24110.5+8640184.813*T0
- S=S+86636.6*Z0+86400.*L5
- S=S/86400.
- SM=myint(S)
- S=S-myint(S)
- T0=S*360.*DR
- T=T+Z0
- // funarg 1
- L=.779072+.00273790931*T
- G=.993126+.0027377785*T
- L=L-myint(L)
- G=G-myint(G)
- L=L*P2
- G=G*P2
- V=.39785*sin(L)
- V=V-.01000*sin(L-G)
- V=V+.00333*sin(L+G)
- V=V-.00021*TT*sin(L)
- U=1-.03349*cos(G)
- U=U-.00014*cos(2*L)
- U=U+.00008*cos(L)
- W=-.00010-.04129*sin(2*L)
- W=W+.03211*sin(G)
- W=W+.00104*sin(2*L-G)
- W=W-.00035*sin(2*L+G)
- W=W-.00008*TT*sin(G)
- S=W/sqrt(U-V*V)
- AA1=L+atan(S/sqrt(1-S*S))
- S=V/sqrt(U)
- DA1=atan(S/sqrt(1-S*S))
- R5=1.00021*sqrt(U)
- T=T+1
- // funarg 2
- L=.779072+.00273790931*T
- G=.993126+.0027377785*T
- L=L-myint(L)
- G=G-myint(G)
- L=L*P2
- G=G*P2
- V=.39785*sin(L)
- V=V-.01000*sin(L-G)
- V=V+.00333*sin(L+G)
- V=V-.00021*TT*sin(L)
- U=1-.03349*cos(G)
- U=U-.00014*cos(2*L)
- U=U+.00008*cos(L)
- W=-.00010-.04129*sin(2*L)
- W=W+.03211*sin(G)
- W=W+.00104*sin(2*L-G)
- W=W-.00035*sin(2*L+G)
- W=W-.00008*TT*sin(G)
- S=W/sqrt(U-V*V)
- AA2=L+atan(S/sqrt(1-S*S))
- S=V/sqrt(U)
- DA2=atan(S/sqrt(1-S*S))
- R5=1.00021*sqrt(U)
- if (AA2 < AA1) {
- AA2=AA2+P2
- }
- Z1=DR*(90.833)
- S=sin(B5*DR)
- C=cos(B5*DR)
- Z=cos(Z1)
- M8=0.
- W8=0.
- A0=AA1
- D0=DA1
- DA=AA2-AA1
- DD=DA2-DA1
- for(C0=0;C0<=23;C0++){
- P=(C0+1.)/24.
- A2=AA1+P*DA
- D2=DA1+P*DD
- K1=15.*DR*1.0027379
- L0=T0+C0*K1
- L2=L0+K1
- H0=L0-A0
- H2=L2-A2
- H1=(H2+H0)/2.
- D1=(D2+D0)/2.
- if (C0<=0.) {
- V0=S*sin(D0)+C*cos(D0)*cos(H0)-Z
- }
- V2=S*sin(D2)+C*cos(D2)*cos(H2)-Z
- if ((V0<0?-1:1)==(V2<0?-1:1)) {
- // return
- A0=A2
- D0=D2
- V0=V2
- continue
- }
- V1=S*sin(D1)+C*cos(D1)*cos(H1)-Z
- A=2.*V2-4.*V1+2.*V0
- B=4.*V1-3.*V0-V2
- D=B*B-4.*A*V0
- if (D<0) {
- // return
- A0=A2
- D0=D2
- V0=V2
- continue
- }
- D=sqrt(D)
- EE=(-B+D)/(2.*A)
- if (EE>1 || EE<0.) {
- EE=(-B-D)/(2.*A)
- }
- T3=C0+EE+1./120.
- H3=myint(T3)
- M3=myint((T3-H3)*60.)
- if (V0<0. && V2>0.) {
- form.SR.value=H3+":"+(M3<10?"0":"")+M3
- M8=1.
- }
- if (V0>0. && V2<0.) {
- form.SS.value=H3+":"+(M3<10?"0":"")+M3
- W8=1.
- }
- H7=H0+EE*(H2-H0)
- N7=-cos(D1)*sin(H7)
- D7=C*sin(D1)-S*cos(D1)*cos(H7)
- AZ=atan(N7/D7)/DR
- if (D7<0.) {
- AZ=AZ+180.
- }
- if (AZ<0.) {
- AZ=AZ+360.
- }
- if (AZ>360) {
- AZ=AZ-360.
- }
- A0=A2
- D0=D2
- V0=V2
- }
- if (M8+W8==0) {
- if (V2<0) {
- form.SR.value="Полярная ночь"
- }
- if (V2>0) {
- form.SR.value="Полярный день"
- }
- }
- if (M8+W8!=0) {
- if (M8==0) {
- form.SR.value="Сегодня нет восхода"
- }
- if (W8==0) {
- form.SS.value="Сегодня нет заката"
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment