Redfern_89

sunrise.js

Oct 20th, 2016
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function init() {
  2.  today= new Date()
  3.  ID=today.getDate()
  4.  IM=today.getMonth()+1
  5.  IY=today.getYear()+1900
  6.  B5=54.58
  7.  L5=52.14
  8.  H=-3
  9.  P1=3.14159265
  10.  P2=2.*P1
  11.  DR=P1/180.
  12.  document.suncalc.ID.value=ID
  13.  document.suncalc.IM.value=IM
  14.  document.suncalc.IY.value=IY
  15.  document.suncalc.B5.value=B5
  16.  document.suncalc.L5.value=L5
  17.  document.suncalc.H.value=H
  18.  document.suncalc.SR.value=""
  19.  document.suncalc.SS.value=""
  20. }
  21.  
  22. function myint(x){
  23.  if (x>=0)
  24.  x=Math.floor(x)
  25.  
  26.  else
  27.  x=Math.ceil(x)
  28.  return x
  29. }
  30.  
  31. function sunrise(form) {
  32.  with (Math){
  33.  ID=parseInt(form.ID.value)
  34.  IM=parseInt(form.IM.value)
  35.  IY=parseInt(form.IY.value)
  36.  B5=parseFloat(form.B5.value)
  37.  L5=parseFloat(form.L5.value)
  38.  H =parseInt(form.H.value)
  39.  form.SR.value=""
  40.  form.SS.value=""
  41.  L5=L5/360.
  42.  Z0=H/24.
  43.  
  44.  G=1
  45.  J3=0
  46.  if (IY<1583){
  47.  G=0
  48.  }
  49.  with(Math){
  50.  D1=myint(ID)
  51.  F=ID-D1-.5
  52.  J=-myint(7*(myint((IM+9)/12)+IY)/4)
  53.  if (G != 0) {
  54.  S=((IM-9)<0?-1:1)
  55.  A=abs(IM-9)
  56.  J3=myint(IY+S*myint(A/7))
  57.  J3=-myint((myint(J3/100)+1)*3/4)
  58.  }
  59.  
  60.  J=J+myint(275*IM/9)+D1+G*J3
  61.  J=J+1721027+2*G+367*IY
  62.  if (F<0) {
  63.  F=F+1
  64.  J=J-1
  65.  }
  66.  }
  67.  
  68.  T=(J-2451545.)+F
  69.  TT=T/36525.+1.
  70.  T0=T/36525.
  71.  S=24110.5+8640184.813*T0
  72.  S=S+86636.6*Z0+86400.*L5
  73.  S=S/86400.
  74.  SM=myint(S)
  75.  S=S-myint(S)
  76.  T0=S*360.*DR
  77.  T=T+Z0
  78. // funarg 1
  79.  L=.779072+.00273790931*T
  80.  G=.993126+.0027377785*T
  81.  L=L-myint(L)
  82.  G=G-myint(G)
  83.  L=L*P2
  84.  G=G*P2
  85.  V=.39785*sin(L)
  86.  V=V-.01000*sin(L-G)
  87.  V=V+.00333*sin(L+G)
  88.  V=V-.00021*TT*sin(L)
  89.  U=1-.03349*cos(G)
  90.  U=U-.00014*cos(2*L)
  91.  U=U+.00008*cos(L)
  92.  W=-.00010-.04129*sin(2*L)
  93.  W=W+.03211*sin(G)
  94.  W=W+.00104*sin(2*L-G)
  95.  W=W-.00035*sin(2*L+G)
  96.  W=W-.00008*TT*sin(G)
  97.  S=W/sqrt(U-V*V)
  98.  AA1=L+atan(S/sqrt(1-S*S))
  99.  S=V/sqrt(U)
  100.  DA1=atan(S/sqrt(1-S*S))
  101.  R5=1.00021*sqrt(U)
  102.  T=T+1
  103.  
  104. // funarg 2
  105.  L=.779072+.00273790931*T
  106.  G=.993126+.0027377785*T
  107.  L=L-myint(L)
  108.  G=G-myint(G)
  109.  L=L*P2
  110.  G=G*P2
  111.  V=.39785*sin(L)
  112.  V=V-.01000*sin(L-G)
  113.  V=V+.00333*sin(L+G)
  114.  V=V-.00021*TT*sin(L)
  115.  U=1-.03349*cos(G)
  116.  U=U-.00014*cos(2*L)
  117.  U=U+.00008*cos(L)
  118.  W=-.00010-.04129*sin(2*L)
  119.  W=W+.03211*sin(G)
  120.  W=W+.00104*sin(2*L-G)
  121.  W=W-.00035*sin(2*L+G)
  122.  W=W-.00008*TT*sin(G)
  123.  S=W/sqrt(U-V*V)
  124.  AA2=L+atan(S/sqrt(1-S*S))
  125.  S=V/sqrt(U)
  126.  DA2=atan(S/sqrt(1-S*S))
  127.  R5=1.00021*sqrt(U)
  128.  if (AA2 < AA1) {
  129.  AA2=AA2+P2
  130.  }
  131.  
  132.  Z1=DR*(90.833)
  133.  
  134.  S=sin(B5*DR)
  135.  C=cos(B5*DR)
  136.  Z=cos(Z1)
  137.  M8=0.
  138.  W8=0.
  139.  A0=AA1
  140.  D0=DA1
  141.  DA=AA2-AA1
  142.  DD=DA2-DA1
  143.  for(C0=0;C0<=23;C0++){
  144.  P=(C0+1.)/24.
  145.  A2=AA1+P*DA
  146.  D2=DA1+P*DD
  147.  K1=15.*DR*1.0027379
  148.  L0=T0+C0*K1
  149.  L2=L0+K1
  150.  H0=L0-A0
  151.  H2=L2-A2
  152.  H1=(H2+H0)/2.
  153.  D1=(D2+D0)/2.
  154.  if (C0<=0.) {
  155.  V0=S*sin(D0)+C*cos(D0)*cos(H0)-Z
  156.  }
  157.  V2=S*sin(D2)+C*cos(D2)*cos(H2)-Z
  158.  
  159.  if ((V0<0?-1:1)==(V2<0?-1:1)) {
  160. // return
  161.  A0=A2
  162.  D0=D2
  163.  V0=V2
  164.  
  165.  continue
  166.  }
  167.  V1=S*sin(D1)+C*cos(D1)*cos(H1)-Z
  168.  A=2.*V2-4.*V1+2.*V0
  169.  B=4.*V1-3.*V0-V2
  170.  D=B*B-4.*A*V0
  171.  if (D<0) {
  172. // return
  173.  A0=A2
  174.  D0=D2
  175.  V0=V2
  176.  continue
  177.  }
  178.  D=sqrt(D)
  179.  EE=(-B+D)/(2.*A)
  180.  if (EE>1 || EE<0.) {
  181.  EE=(-B-D)/(2.*A)
  182.  }
  183.  T3=C0+EE+1./120.
  184.  H3=myint(T3)
  185.  M3=myint((T3-H3)*60.)
  186.  if (V0<0. && V2>0.) {
  187.  form.SR.value=H3+":"+(M3<10?"0":"")+M3
  188.  M8=1.
  189.  }
  190.  if (V0>0. && V2<0.) {
  191.  form.SS.value=H3+":"+(M3<10?"0":"")+M3
  192.  W8=1.
  193.  }
  194.  H7=H0+EE*(H2-H0)
  195.  N7=-cos(D1)*sin(H7)
  196.  D7=C*sin(D1)-S*cos(D1)*cos(H7)
  197.  AZ=atan(N7/D7)/DR
  198.  if (D7<0.) {
  199.  AZ=AZ+180.
  200.  }
  201.  if (AZ<0.) {
  202.  AZ=AZ+360.
  203.  }
  204.  if (AZ>360) {
  205.  AZ=AZ-360.
  206.  }
  207.  
  208.  A0=A2
  209.  D0=D2
  210.  V0=V2
  211.  
  212.  }
  213.  
  214.  
  215.  if (M8+W8==0) {
  216.  if (V2<0) {
  217.  form.SR.value="Полярная ночь"
  218.  }
  219.  if (V2>0) {
  220.  form.SR.value="Полярный день"
  221.  }
  222.  }
  223.  if (M8+W8!=0) {
  224.  if (M8==0) {
  225.  form.SR.value="Сегодня нет восхода"
  226.  }
  227.  if (W8==0) {
  228.  form.SS.value="Сегодня нет заката"
  229.  }
  230.  }
  231.  
  232.  
  233.  }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment