void get_coord(double * lat, double * lon)
{
- *lat = 55.166666;
- *lon = 30.166666;
+ /* coordinates St.-Petersburg */
+ *lat = 59.883333;
+ *lon = 30.25;
+
+ /* coordinates Vitebsk */
+ //*lat = 55.166666;
+ //*lon = 30.133333;
+
+
}
double
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;
+ struct tm;
double alt, hour1, hour2, hh, x;
- int hour, min;
sun_rise_set(lon, lat,
year, month, day,
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 / (alt_max + 5); // sun height in percent
+ //printf("max = %f alt = %f ",alt_max, *alt);
+ *alt = *alt / (alt_max + 10); // sun height in percent
+ //printf("alt1 = %f \n", *alt);
*azm = azimuth(lon, lat, year, month, day, hour, min, zone);
+ //printf("azm = %f ", *azm);
//if south latitude
if (lat < 0){
*azm = 75 + (75 - *azm);
*azm = fmod(*azm, 380);
}
- *azm = (*azm - 75) / 190; // sun azimuth in percent
+ *azm = (*azm - 75) / 210; // sun azimuth in percent
+ //printf("azm1 = %f \n", *azm);
}
time_t get_next_sunrise()
{
if (alt > -7 && alt < 7 && azm < 50) return TIME_SUNRISE;
if (alt > -7 && alt < 7 && azm > 50) return TIME_SUNSET;
if (alt >= 7) return TIME_DAY;
-
+ return TIME_DAY;
}
+
int get_moon_phase()
{
int year, month, day, hour, min, zone;
double phase;
get_localtime(&year, &month, &day, &hour, &min, &zone);
phase = moon_phase(year, month, day) * 100;
- printf("ph = %f\n", phase);
+ /* printf("ph = %f\n", phase); */
if (phase <= 3 || phase >=97) return MOON_NONE;
if (phase > 5 && phase <= 25) return MOON_GROWS;
if (phase > 25 && phase <= 45) return MOON_GROWSHALF;
if (phase > 45 && phase <= 55) return MOON_FULL;
if (phase > 55 && phase <= 75) return MOON_DECREASHALF;
if (phase > 75 && phase < 97) return MOON_DECREAS;
+ return MOON_NONE;
+
}
+
+gint
+fast_rnd(gint max)
+{
+ guint offset = 12923;
+ guint multiplier = 4079;
+ static guint seed = 123;
+
+ seed = seed * multiplier + offset;
+ return (gint)(seed % max);
+}
+void
+get_sun_screen_pos(double alt, double azm, gint * x, gint * y)
+{
+ gint y0 = 365;// - уровень горизонта
+ *x = (int)(azm * 800) - 64;
+ *y = (int)((1 - alt) * y0) - 64;
+ //fprintf(stderr, "sun pos alt=%f azm=%f x=%d y=%d\n", alt, azm, *x, *y);
+}
+