changed sun algorithm
authortanya <tanya@tanin.oblgaz>
Fri, 9 Apr 2010 16:54:48 +0000 (19:54 +0300)
committertanya <tanya@tanin.oblgaz>
Fri, 9 Apr 2010 16:54:48 +0000 (19:54 +0300)
applet/data/theme/Modern/sky3.png
applet/src/livewp-home-widget.c
applet/src/livewp-rules.c

index 33f605d..a55c4b2 100755 (executable)
Binary files a/applet/data/theme/Modern/sky3.png and b/applet/data/theme/Modern/sky3.png differ
index ae4baae..6537b75 100644 (file)
@@ -608,6 +608,7 @@ get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
          o_height = 128; 
     *x = (int)(azm * 800) - 64;
     *y = (int)((1 - alt) * y0) - 64;
+    //fprintf(stderr, "sun pos x=%d y=%d\n", *x, *y);
 }
 
 void change_multiactor()
@@ -711,7 +712,6 @@ plugin_on_timeout (AWallpaperPlugin *desktop_plugin)
   time_t now;
   gint t;
 
-
   Actor *actor;
 fprintf(stderr, "timer daytime=%d\n", daytime);
   if (scene.daytime != daytime){
index 7daab8b..43cd24b 100644 (file)
@@ -54,27 +54,49 @@ void get_coord(double * lat, double * lon)
 }
 
 double
-get_max_sun_alt(double lon, double lat, int year, int month, int day)
+get_max_sun_alt(double lon, double lat, int year, int month, int day, int zone)
 {
+    int h1, m1, h2, m2, h, m;
+    time_t t1, t2, t;
+    struct tm tm1, tm2;
+    double alt, hour1, hour2, hh, x;
+    int hour, min;
+
+    sun_rise_set(lon, lat,
+                 year, month, day, 
+                 zone,
+                 &h1, &m1, &h2, &m2);
+    //printf("h1=%d m1=%d h2=%d m2=%d\n", h1, m1, h2, m2);
+    
+    hour1 = (double)h1 + (double)m1/60;
+    hour2 = (double)h2 + (double)m2/60;
+
+    hh = (hour2 - hour1) / 2 + hour1;
+    h = floor(hh);
+    m = (modf(hh, &x) * 60);
     
+    alt = altitude(lon, lat, year, month, day, h, m, zone);
+    //printf("alt = %f \n", alt);
+    return alt;
 }
 
 void get_sun_pos(double * alt, double * azm)
 {
     int year, month, day, hour, min, zone;
-    double lat, lon;
+    double lat, lon, alt_max;
     get_localtime(&year, &month, &day, &hour, &min, &zone);
     get_coord(&lat, &lon);
+    alt_max = get_max_sun_alt(lon, lat, year, month, day, zone);
     *alt = altitude(lon, lat, year, month, day, hour, min, zone);
-    *alt = *alt / 70; // sun height in percent
+    *alt = *alt / (alt_max + 5); // sun height in percent
 
     *azm = azimuth(lon, lat, year, month, day, hour, min, zone);
     //if south latitude
     if (lat < 0){
-        *azm = 90 + (90 - *azm);
-        *azm = fmod(*azm, 360);
+        *azm = 75 + (75 - *azm);
+        *azm = fmod(*azm, 380);
     }
-    *azm = (*azm - 90) / 180; // sun azimuth in percent
+    *azm = (*azm - 75) / 190; // sun azimuth in percent
 }
 time_t get_next_sunrise()
 {