newtime 8

stars, planets, phases of the moon, season, clouds, sunrises and sunsets.

-- data

-- hyg star catalog
-- top 1001 stars by magnitude
-- right ascension, declination, spectra
hyg = {{0.0014,0.4666,8}, {0.0026,0.4037,12}, {0.0058,0.6616,12}, {0.0064,0.8286,15}, {0.0065,0.2458,9}, {0.0092,0.5844,12}, {0.0102,0.3948,8}, {0.0127,0.7044,6}, {0.0135,0.4510,9}, {0.0139,0.1396,15}, {0.0178,0.0708,10}, {0.0182,0.2573,6}, {0.0183,0.2650,9}, {0.0219,0.1502,12}, {0.0219,0.1502,6}, {0.0229,0.8496,12}, {0.0256,0.6873,12}, {0.0257,0.7994,12}, {0.0268,0.6628,10}, {0.0273,0.6715,9}, {0.0281,0.8141,9}, {0.0301,0.1808,6}, {0.0303,0.4001,9}, {0.0311,0.7682,12}, {0.0329,0.6348,9}, {0.0338,0.5421,9}, {0.0341,0.8212,10}, {0.0346,0.7282,12}, {0.0394,0.8373,12}, {0.0394,0.7139,6}, {0.0397,0.6301,10}, {0.0407,0.3369,12}, {0.0437,0.5438,9}, {0.0459,0.2405,10}, {0.0475,0.1931,12}, {0.0476,0.4434,9}, {0.0477,0.9792,9}, {0.0483,0.7625,12}, {0.0484,0.6979,8}, {0.0494,0.8064,6}, {0.0498,0.6672,9}, {0.0526,0.1174,15}, {0.0583,0.4545,9}, {0.0596,0.8346,6}, {0.0614,0.2593,9}, {0.0634,0.2274,9}, {0.0635,0.5853,10}, {0.0672,0.7300,15}, {0.0679,0.1820,12}, {0.0681,0.7702,9}, {0.0704,0.5305,9}, {0.0720,0.7816,12}, {0.0723,0.4115,10}, {0.0732,0.5509,9}, {0.0774,0.4426,9}, {0.0785,0.6643,15}, {0.0788,0.6072,6}, {0.0789,0.2428,8}, {0.0794,0.8537,12}, {0.0796,0.6156,6}, {0.0805,0.2133,10}, {0.0825,0.1579,15}, {0.0833,0.3829,9}, {0.0847,0.8939,6}, {0.0848,0.5154,6}, {0.0857,0.9023,6}, {0.0860,0.7352,12}, {0.0883,0.6303,9}, {0.0900,0.6944,6}, {0.0924,0.5491,10}, {0.0948,0.2138,12}, {0.0954,0.6880,6}, {0.0984,0.1186,6}, {0.1021,0.2350,12}, {0.1029,0.5470,12}, {0.1035,0.8745,6}, {0.1054,0.9959,15}, {0.1108,0.5018,12}, {0.1108,0.1207,12}, {0.1116,0.2786,9}, {0.1134,0.5180,6}, {0.1140,0.4230,12}, {0.1140,0.7735,15}, {0.1145,0.5562,15}, {0.1147,0.3968,15}, {0.1166,0.6625,9}, {0.1174,0.3200,10}, {0.1180,0.6514,12}, {0.1185,0.7129,15}, {0.1185,0.8105,9}, {0.1191,0.6948,9}, {0.1210,0.7931,10}, {0.1225,0.4506,9}, {0.1238,0.2761,6}, {0.1266,0.5227,8}, {0.1267,0.3688,6}, {0.1283,0.7973,10}, {0.1286,0.7158,8}, {0.1307,0.7275,12}, {0.1313,0.7756,10}, {0.1316,0.7492,9}, {0.1331,0.6096,9}, {0.1334,0.3390,15}, {0.1386,0.3791,8}, {0.1388,0.2607,10}, {0.1391,0.6614,9}, {0.1419,0.7770,15}, {0.1422,0.5502,10}, {0.1439,0.5541,12}, {0.1452,0.8330,12}, {0.1458,0.8271,6}, {0.1462,0.7666,9}, {0.1464,0.5719,9}, {0.1479,0.4475,9}, {0.1485,0.3798,12}, {0.1503,0.7677,12}, {0.1506,0.5022,15}, {0.1508,0.2763,9}, {0.1548,0.7655,12}, {0.1550,0.4458,9}, {0.1557,0.1400,9}, {0.1558,0.6794,12}, {0.1562,0.6340,12}, {0.1564,0.7365,15}, {0.1564,0.6359,12}, {0.1568,0.6354,12}, {0.1570,0.4328,8}, {0.1572,0.6330,12}, {0.1575,0.3708,15}, {0.1578,0.0876,8}, {0.1580,0.6339,12}, {0.1587,0.2910,6}, {0.1591,0.6336,12}, {0.1593,0.2989,10}, {0.1594,0.8640,8}, {0.1626,0.6771,12}, {0.1627,0.4836,10}, {0.1652,0.7223,12}, {0.1653,0.4250,8}, {0.1658,0.1589,8}, {0.1659,0.6988,1}, {0.1671,0.5694,12}, {0.1673,0.1547,8}, {0.1689,0.5333,6}, {0.1699,0.6227,9}, {0.1712,0.7797,6}, {0.1727,0.7651,12}, {0.1749,0.4620,15}, {0.1764,0.2650,9}, {0.1767,0.1529,10}, {0.1770,0.7689,10}, {0.1773,0.4575,9}, {0.1775,0.5494,12}, {0.1778,0.2140,15}, {0.1781,0.1705,9}, {0.1791,0.3122,12}, {0.1804,0.5868,10}, {0.1826,0.5975,10}, {0.1834,0.3110,9}, {0.1843,0.6239,6}, {0.1844,0.5996,6}, {0.1849,0.6267,6}, {0.1850,0.5868,15}, {0.1865,0.5887,10}, {0.1865,0.6066,9}, {0.1866,0.5882,6}, {0.1899,0.3346,9}, {0.1903,0.1942,6}, {0.1914,0.3302,10}, {0.1914,0.5564,6}, {0.1916,0.5917,9}, {0.1919,0.4814,12}, {0.1921,0.7292,10}, {0.1932,0.5695,6}, {0.1932,0.4205,9}, {0.1948,0.3907,8}, {0.1948,0.2674,15}, {0.1960,0.6275,12}, {0.1983,0.4819,12}, {0.2013,0.5387,15}, {0.2018,0.5494,6}, {0.2022,0.5311,12}, {0.2034,0.4697,6}, {0.2042,0.8686,1}, {0.2043,0.5136,12}, {0.2058,0.5751,9}, {0.2062,0.6843,9}, {0.2064,0.7986,6}, {0.2073,0.5095,9}, {0.2097,0.7435,15}, {0.2101,0.7282,9}, {0.2107,0.8358,10}, {0.2114,0.3029,9}, {0.2121,0.3757,9}, {0.2129,0.7291,12}, {0.2138,0.4717,6}, {0.2147,0.4514,12}, {0.2169,0.4341,12}, {0.2173,0.4100,8}, {0.2175,0.4281,12}, {0.2176,0.5159,9}, {0.2184,0.4544,12}, {0.2199,0.7556,10}, {0.2199,0.7555,8}, {0.2206,0.4620,12}, {0.2210,0.6854,9}, {0.2219,0.4268,12}, {0.2250,0.4566,10}, {0.2253,0.4867,12}, {0.2258,0.5353,12}, {0.2266,0.6589,12}, {0.2279,0.3847,10}, {0.2297,0.5330,12}, {0.2300,0.3029,9}, {0.2306,0.4983,1}, {0.2307,0.6033,8}, {0.2311,0.4010,15}, {0.2317,0.1528,15}, {0.2325,0.5527,12}, {0.2327,0.5552,1}, {0.2329,0.4731,12}, {0.2329,0.4672,1}, {0.2335,0.4933,12}, {0.2340,0.5516,10}, {0.2345,0.6175,12}, {0.2352,0.4856,1}, {0.2355,0.5229,12}, {0.2359,0.3107,12}, {0.2366,0.4892,1}, {0.2392,0.3753,15}, {0.2394,0.1348,6}, {0.2409,0.4177,6}, {0.2412,0.2163,6}, {0.2415,0.4463,12}, {0.2425,0.7177,10}, {0.2429,0.1880,9}, {0.2437,0.3013,9}, {0.2440,0.3840,10}, {0.2441,0.7175,9}, {0.2454,0.6534,6}, {0.2461,0.6126,10}, {0.2466,0.5412,8}, {0.2475,0.4213,15}, {0.2483,0.3040,12}, {0.2494,0.2621,9}, {0.2497,0.8016,9}, {0.2497,0.7497,6}, {0.2498,0.7067,6}, {0.2500,0.7552,8}, {0.2500,0.4829,9}, {0.2517,0.5536,6}, {0.2529,0.6292,10}, {0.2553,0.5820,12}, {0.2583,0.5789,12}, {0.2603,0.4651,9}, {0.2603,0.6250,8}, {0.2607,0.6639,10}, {0.2615,0.3048,10}, {0.2636,0.8278,6}, {0.2641,0.3330,12}, {0.2654,0.3142,10}, {0.2658,0.4002,12}, {0.2659,0.6251,8}, {0.2665,0.5255,6}, {0.2666,0.2072,15}, {0.2696,0.3190,12}, {0.2700,0.4609,12}, {0.2701,0.6123,12}, {0.2721,0.3699,12}, {0.2728,0.5407,6}, {0.2743,0.2057,12}, {0.2743,0.3724,6}, {0.2755,0.3930,9}, {0.2762,0.5911,6}, {0.2762,0.2600,12}, {0.2763,0.3987,9}, {0.2805,0.6396,6}, {0.2805,0.5735,9}, {0.2814,0.4071,6}, {0.2815,0.5716,15}, {0.2832,0.5134,9}, {0.2835,0.1559,6}, {0.2846,0.3194,12}, {0.2846,0.2021,10}, {0.2847,0.2188,9}, {0.2867,0.6887,6}, {0.2876,0.3656,9}, {0.2876,0.4331,9}, {0.2890,0.4053,12}, {0.2898,0.8246,10}, {0.2907,0.3390,12}, {0.2917,0.9277,9}, {0.2929,0.3448,9}, {0.2938,0.3676,12}, {0.2943,0.4131,12}, {0.2945,0.6143,10}, {0.2975,0.3534,15}, {0.2977,0.1083,10}, {0.2994,0.6680,9}, {0.2999,0.4973,6}, {0.3004,0.2402,15}, {0.3011,0.2520,8}, {0.3016,0.3536,12}, {0.3020,0.3513,12}, {0.3034,0.1225,15}, {0.3036,0.2939,9}, {0.3042,0.5919,6}, {0.3047,0.3614,1}, {0.3056,0.6221,15}, {0.3084,0.3372,12}, {0.3095,0.6544,10}, {0.3105,0.5461,12}, {0.3112,0.5496,9}, {0.3119,0.6766,15}, {0.3120,0.2594,9}, {0.3124,0.5667,9}, {0.3153,0.3761,15}, {0.3157,0.6772,6}, {0.3157,0.6772,6}, {0.3166,0.6494,9}, {0.3176,0.3057,12}, {0.3186,0.3511,12}, {0.3190,0.5290,15}, {0.3203,0.4469,9}, {0.3207,0.0966,9}, {0.3217,0.6605,9}, {0.3221,0.3391,6}, {0.3225,0.6355,10}, {0.3231,0.2891,9}, {0.3231,0.6557,9}, {0.3251,0.3559,12}, {0.3259,0.2424,12}, {0.3259,0.3619,10}, {0.3279,0.2746,10}, {0.3282,0.2841,12}, {0.3287,0.2328,12}, {0.3311,0.2057,12}, {0.3312,0.3729,15}, {0.3321,0.2264,12}, {0.3349,0.5130,9}, {0.3358,0.2778,1}, {0.3386,0.3650,15}, {0.3388,0.1188,12}, {0.3393,0.4834,10}, {0.3396,0.3931,12}, {0.3400,0.2370,1}, {0.3412,0.2799,9}, {0.3431,0.2758,9}, {0.3448,0.5510,9}, {0.3462,0.0727,15}, {0.3462,0.2963,6}, {0.3477,0.0695,9}, {0.3490,0.1694,9}, {0.3492,0.7399,9}, {0.3512,0.4783,6}, {0.3512,0.1326,9}, {0.3544,0.8373,10}, {0.3595,0.2612,6}, {0.3595,0.5317,6}, {0.3602,0.5186,9}, {0.3612,0.3038,10}, {0.3613,0.2060,12}, {0.3615,0.1680,12}, {0.3615,0.2408,15}, {0.3634,0.5189,12}, {0.3636,0.3156,12}, {0.3642,0.2631,10}, {0.3644,0.6009,9}, {0.3644,0.1961,6}, {0.3653,0.2442,6}, {0.3655,0.4247,10}, {0.3658,0.6598,10}, {0.3658,0.1846,12}, {0.3658,0.5357,10}, {0.3670,0.5324,6}, {0.3684,0.3461,9}, {0.3716,0.1631,12}, {0.3718,0.5330,10}, {0.3739,0.5659,6}, {0.3745,0.7669,6}, {0.3751,0.2708,15}, {0.3754,0.7321,15}, {0.3767,0.1311,6}, {0.3775,0.7620,6}, {0.3779,0.2383,9}, {0.3786,0.0967,15}, {0.3795,0.7136,10}, {0.3806,0.2587,9}, {0.3812,0.7867,6}, {0.3826,0.1724,12}, {0.3828,0.1538,12}, {0.3842,0.1127,6}, {0.3850,0.5129,12}, {0.3863,0.1803,8}, {0.3869,0.1707,6}, {0.3881,0.7045,6}, {0.3896,0.6911,8}, {0.3904,0.1944,12}, {0.3921,0.6455,9}, {0.3942,0.4519,9}, {0.3953,0.3003,9}, {0.3963,0.2752,15}, {0.3967,0.1831,9}, {0.3969,0.8503,15}, {0.3970,0.6276,9}, {0.3972,0.4934,6}, {0.3978,0.7871,15}, {0.3988,0.7022,10}, {0.3989,0.1709,12}, {0.3989,0.8879,10}, {0.3992,0.7892,6}, {0.4006,0.2258,6}, {0.4008,0.9518,9}, {0.4023,0.1593,12}, {0.4027,0.4937,9}, {0.4036,0.5550,6}, {0.4064,0.1527,10}, {0.4068,0.6321,10}, {0.4077,0.1385,6}, {0.4104,0.8280,15}, {0.4107,0.4175,10}, {0.4109,0.2414,10}, {0.4112,0.8004,6}, {0.4116,0.6445,9}, {0.4145,0.1968,12}, {0.4218,0.5931,6}, {0.4218,0.6958,6}, {0.4222,0.5555,9}, {0.4222,0.4979,6}, {0.4225,0.5665,12}, {0.4240,0.4314,9}, {0.4262,0.1109,12}, {0.4269,0.2660,6}, {0.4283,0.6301,15}, {0.4285,0.1593,9}, {0.4285,0.7384,6}, {0.4305,0.6102,9}, {0.4312,0.1886,12}, {0.4322,0.7306,8}, {0.4336,0.0887,15}, {0.4348,0.4065,9}, {0.4355,0.3274,9}, {0.4360,0.1737,15}, {0.4360,0.7039,10}, {0.4389,0.1573,12}, {0.4395,0.5517,12}, {0.4413,0.0633,8}, {0.4414,0.1802,9}, {0.4426,0.2321,6}, {0.4440,0.1911,10}, {0.4465,0.1423,12}, {0.4469,0.1635,9}, {0.4485,0.0526,12}, {0.4491,0.2254,10}, {0.4511,0.4100,9}, {0.4537,0.6901,9}, {0.4538,0.1730,9}, {0.4553,0.6375,6}, {0.4582,0.3983,9}, {0.4584,0.2654,6}, {0.4596,0.8132,6}, {0.4600,0.6121,6}, {0.4609,0.8431,15}, {0.4643,0.1724,10}, {0.4650,0.7472,9}, {0.4664,0.3732,6}, {0.4681,0.6140,6}, {0.4682,0.5857,6}, {0.4689,0.6283,8}, {0.4699,0.4797,6}, {0.4710,0.6752,10}, {0.4712,0.6839,9}, {0.4718,0.4179,9}, {0.4729,0.1973,12}, {0.4730,0.5335,12}, {0.4749,0.5585,15}, {0.4756,0.4018,6}, {0.4801,0.8852,8}, {0.4813,0.3230,10}, {0.4832,0.1499,12}, {0.4840,0.4954,10}, {0.4900,0.1293,6}, {0.4902,0.5363,8}, {0.4903,0.7654,9}, {0.4906,0.1601,10}, {0.4917,0.6123,6}, {0.4924,0.5810,6}, {0.4928,0.1456,12}, {0.4935,0.5098,15}, {0.4939,0.2490,9}, {0.4951,0.3116,6}, {0.4957,0.7983,6}, {0.5021,0.1483,6}, {0.5036,0.5485,10}, {0.5048,0.1410,15}, {0.5056,0.2185,12}, {0.5058,0.2182,12}, {0.5058,0.3626,15}, {0.5070,0.3743,9}, {0.5081,0.2091,12}, {0.5105,0.1736,12}, {0.5107,0.8168,6}, {0.5110,0.4025,12}, {0.5122,0.1224,8}, {0.5127,0.0594,12}, {0.5128,0.1444,12}, {0.5138,0.4963,6}, {0.5148,0.1644,9}, {0.5185,0.1494,12}, {0.5187,0.6570,9}, {0.5195,0.2209,12}, {0.5207,0.4082,12}, {0.5216,0.1827,8}, {0.5223,0.4100,15}, {0.5225,0.0993,12}, {0.5233,0.8877,12}, {0.5234,0.7298,10}, {0.5239,0.3700,10}, {0.5258,0.1159,12}, {0.5262,0.2303,6}, {0.5288,0.2280,6}, {0.5289,0.4919,15}, {0.5289,0.4919,15}, {0.5321,0.1216,12}, {0.5331,0.1684,12}, {0.5369,0.2281,9}, {0.5371,0.2768,6}, {0.5375,0.8109,6}, {0.5379,0.1823,12}, {0.5386,0.5189,8}, {0.5389,0.7129,6}, {0.5432,0.5609,10}, {0.5432,0.1025,9}, {0.5465,0.2227,12}, {0.5486,0.4692,6}, {0.5486,0.5974,15}, {0.5499,0.6549,10}, {0.5502,0.1671,12}, {0.5548,0.3713,10}, {0.5560,0.2960,6}, {0.5574,0.1612,12}, {0.5583,0.8051,6}, {0.5583,0.8051,6}, {0.5583,0.1415,10}, {0.5592,0.4380,12}, {0.5592,0.8055,6}, {0.5632,0.2811,10}, {0.5658,0.4967,6}, {0.5694,0.2030,12}, {0.5734,0.3164,15}, {0.5745,0.5970,15}, {0.5747,0.7740,12}, {0.5760,0.3086,8}, {0.5760,0.5878,9}, {0.5760,0.2684,12}, {0.5761,0.2640,12}, {0.5774,0.8596,8}, {0.5777,0.3167,12}, {0.5796,0.6022,10}, {0.5802,0.2373,12}, {0.5821,0.2661,12}, {0.5824,0.2511,12}, {0.5845,0.5086,6}, {0.5845,0.2466,15}, {0.5860,0.1646,12}, {0.5864,0.8576,6}, {0.5875,0.2712,12}, {0.5878,0.3518,9}, {0.5880,0.2979,9}, {0.5923,0.4429,9}, {0.5927,0.7877,6}, {0.5942,0.6066,9}, {0.5945,0.4667,15}, {0.5947,0.7560,6}, {0.5966,0.4257,6}, {0.5968,0.2441,12}, {0.5974,0.1867,12}, {0.5976,0.2895,6}, {0.5993,0.2805,12}, {0.6008,0.7881,15}, {0.6015,0.2488,12}, {0.6015,0.2479,6}, {0.6020,0.0352,9}, {0.6024,0.9205,9}, {0.6054,0.6687,9}, {0.6056,0.7128,6}, {0.6060,0.2197,12}, {0.6074,0.6653,15}, {0.6080,0.2658,12}, {0.6096,0.2254,12}, {0.6108,0.1620,9}, {0.6109,0.1620,10}, {0.6116,0.5912,12}, {0.6119,0.5763,6}, {0.6125,0.2367,12}, {0.6125,0.2900,12}, {0.6129,0.1390,15}, {0.6132,0.4686,15}, {0.6137,0.3046,9}, {0.6146,0.6504,6}, {0.6155,0.5105,6}, {0.6166,0.0609,9}, {0.6183,0.3447,9}, {0.6185,0.9120,9}, {0.6187,0.4109,6}, {0.6190,0.6061,10}, {0.6192,0.2579,12}, {0.6230,0.4759,15}, {0.6240,0.2604,12}, {0.6244,0.2661,12}, {0.6264,0.7244,10}, {0.6270,0.5116,9}, {0.6278,0.3595,8}, {0.6281,0.6497,9}, {0.6286,0.2386,12}, {0.6311,0.2484,12}, {0.6333,0.2292,12}, {0.6335,0.3900,6}, {0.6335,0.2106,10}, {0.6358,0.6851,10}, {0.6368,0.4479,12}, {0.6372,0.1733,6}, {0.6374,0.3325,9}, {0.6379,0.2340,12}, {0.6381,0.1184,6}, {0.6394,0.8991,6}, {0.6398,0.2742,12}, {0.6401,0.2985,9}, {0.6408,0.2517,12}, {0.6411,0.2952,12}, {0.6412,0.1704,12}, {0.6420,0.7077,15}, {0.6423,0.8276,9}, {0.6443,0.6617,15}, {0.6479,0.6742,12}, {0.6491,0.6484,6}, {0.6492,0.5585,15}, {0.6494,0.2713,12}, {0.6497,0.4178,9}, {0.6499,0.2502,12}, {0.6505,0.1316,9}, {0.6507,0.3437,9}, {0.6514,0.2635,9}, {0.6518,0.3346,12}, {0.6539,0.6093,6}, {0.6547,0.6461,6}, {0.6556,0.9322,6}, {0.6557,0.5357,9}, {0.6571,0.5857,6}, {0.6573,0.5409,10}, {0.6588,0.6008,8}, {0.6595,0.4809,6}, {0.6603,0.5249,6}, {0.6604,0.3132,12}, {0.6624,0.4071,9}, {0.6633,0.1476,15}, {0.6642,0.5870,15}, {0.6645,0.3377,12}, {0.6650,0.6493,9}, {0.6659,0.3549,12}, {0.6668,0.2867,12}, {0.6669,0.3743,12}, {0.6680,0.8254,15}, {0.6704,0.3900,12}, {0.6712,0.2955,12}, {0.6714,0.3852,12}, {0.6718,0.3841,10}, {0.6728,0.7496,12}, {0.6750,0.3919,12}, {0.6752,0.3449,12}, {0.6766,0.4795,8}, {0.6774,0.1462,10}, {0.6794,0.4739,10}, {0.6804,0.7573,12}, {0.6804,0.2214,10}, {0.6810,0.3657,6}, {0.6814,0.3578,12}, {0.6819,0.6064,6}, {0.6833,0.8417,10}, {0.6834,0.3887,9}, {0.6843,0.5780,12}, {0.6844,0.3697,12}, {0.6854,0.3975,12}, {0.6855,0.2358,12}, {0.6871,0.3532,8}, {0.6877,0.6194,10}, {0.6881,0.5110,6}, {0.6883,0.4077,10}, {0.6885,0.3072,12}, {0.6890,0.3807,6}, {0.6899,0.0617,9}, {0.6903,0.7358,12}, {0.6916,0.3432,12}, {0.6919,0.3041,9}, {0.6925,0.4413,1}, {0.6953,0.6756,15}, {0.6965,0.7162,10}, {0.6966,0.0693,9}, {0.6986,0.9558,10}, {0.7005,0.1165,9}, {0.7012,0.1720,9}, {0.7015,0.3095,9}, {0.7027,0.2886,12}, {0.7030,0.2888,12}, {0.7042,0.5565,12}, {0.7046,0.2647,9}, {0.7067,0.5521,9}, {0.7074,0.1889,9}, {0.7080,0.2047,9}, {0.7085,0.6718,6}, {0.7144,0.8651,12}, {0.7155,0.4126,6}, {0.7155,0.4126,6}, {0.7168,0.2598,15}, {0.7185,0.5799,8}, {0.7188,0.6380,6}, {0.7188,0.7045,9}, {0.7190,0.3522,9}, {0.7228,0.4286,6}, {0.7229,0.3827,15}, {0.7236,0.3611,12}, {0.7248,0.7064,12}, {0.7259,0.1915,9}, {0.7260,0.1868,12}, {0.7266,0.3657,6}, {0.7267,0.5230,9}, {0.7268,0.4717,15}, {0.7273,0.3341,15}, {0.7295,0.7906,10}, {0.7297,0.6451,9}, {0.7297,0.2928,12}, {0.7299,0.1629,12}, {0.7304,0.2229,12}, {0.7307,0.9810,6}, {0.7317,0.2939,12}, {0.7326,0.5698,6}, {0.7331,0.2416,6}, {0.7337,0.2854,10}, {0.7342,0.2611,15}, {0.7344,0.4145,15}, {0.7346,0.4549,12}, {0.7357,0.7556,12}, {0.7371,0.4285,6}, {0.7375,0.9008,15}, {0.7378,0.2832,12}, {0.7385,0.5254,9}, {0.7401,0.1404,9}, {0.7406,0.6540,10}, {0.7414,0.3454,15}, {0.7414,0.2771,15}, {0.7416,0.5150,6}, {0.7430,0.2942,9}, {0.7455,0.8160,9}, {0.7474,0.7069,9}, {0.7476,0.7860,9}, {0.7484,0.6625,9}, {0.7490,0.6677,15}, {0.7493,0.4457,9}, {0.7504,0.5163,12}, {0.7510,0.6200,10}, {0.7512,0.5073,6}, {0.7538,0.5139,9}, {0.7540,0.3310,9}, {0.7546,0.2217,12}, {0.7551,0.5531,6}, {0.7552,0.6598,12}, {0.7556,0.3419,9}, {0.7560,0.1463,6}, {0.7561,0.6156,12}, {0.7578,0.2447,10}, {0.7596,0.3830,12}, {0.7622,0.2958,8}, {0.7638,0.7004,9}, {0.7644,0.8963,6}, {0.7646,0.3343,9}, {0.7646,0.9041,15}, {0.7648,0.4839,9}, {0.7661,0.1584,8}, {0.7665,0.6209,9}, {0.7668,0.3090,12}, {0.7687,0.2446,12}, {0.7694,0.3588,9}, {0.7700,0.2274,10}, {0.7744,0.4542,9}, {0.7757,0.7155,6}, {0.7799,0.1032,9}, {0.7811,0.7089,6}, {0.7817,0.3501,12}, {0.7817,0.6141,15}, {0.7827,0.6010,6}, {0.7828,0.4736,10}, {0.7848,0.6853,6}, {0.7863,0.1545,12}, {0.7879,0.7050,8}, {0.7880,0.6258,10}, {0.7884,0.3539,12}, {0.7884,0.7441,8}, {0.7895,0.1265,15}, {0.7901,0.3827,10}, {0.7909,0.6816,12}, {0.7914,0.5837,9}, {0.7928,0.4681,9}, {0.7935,0.3340,6}, {0.7949,0.3792,9}, {0.7954,0.5770,6}, {0.7960,0.4729,12}, {0.7961,0.2941,15}, {0.7965,0.3463,9}, {0.7975,0.2750,9}, {0.7982,0.2894,6}, {0.7984,0.3832,15}, {0.7986,0.2814,9}, {0.8004,0.8759,10}, {0.8012,0.7175,12}, {0.8025,0.9075,9}, {0.8030,0.7119,9}, {0.8035,0.7965,9}, {0.8067,0.4008,15}, {0.8068,0.4114,15}, {0.8074,0.2530,12}, {0.8078,0.2511,15}, {0.8083,0.2744,12}, {0.8094,0.5173,15}, {0.8116,0.6370,8}, {0.8123,0.7874,6}, {0.8130,0.6553,9}, {0.8153,0.5410,9}, {0.8170,0.7790,15}, {0.8172,0.4929,12}, {0.8195,0.6001,10}, {0.8202,0.5971,10}, {0.8229,0.7507,12}, {0.8238,0.5590,9}, {0.8246,0.6030,8}, {0.8251,0.8904,10}, {0.8269,0.5493,6}, {0.8281,0.5056,15}, {0.8288,0.6338,12}, {0.8300,0.2674,9}, {0.8301,0.5356,10}, {0.8308,0.6949,9}, {0.8312,0.3491,9}, {0.8325,0.6083,9}, {0.8332,0.3040,12}, {0.8337,0.0949,6}, {0.8352,0.3461,8}, {0.8353,0.8771,9}, {0.8394,0.1323,10}, {0.8395,0.9317,12}, {0.8412,0.4954,12}, {0.8426,0.8143,6}, {0.8428,0.7597,9}, {0.8441,0.7651,9}, {0.8443,0.6545,9}, {0.8456,0.4305,10}, {0.8459,0.4303,10}, {0.8479,0.4179,6}, {0.8488,0.7236,15}, {0.8499,0.6788,9}, {0.8511,0.1848,12}, {0.8537,0.6687,15}, {0.8539,0.8500,6}, {0.8564,0.5628,12}, {0.8594,0.5811,15}, {0.8594,0.2373,9}, {0.8600,0.4939,10}, {0.8609,0.5884,12}, {0.8621,0.7516,6}, {0.8635,0.5837,6}, {0.8639,0.2116,6}, {0.8646,0.1322,6}, {0.8648,0.8435,9}, {0.8648,0.8199,15}, {0.8650,0.6707,9}, {0.8653,0.3596,15}, {0.8654,0.6887,9}, {0.8657,0.5896,9}, {0.8663,0.7027,12}, {0.8664,0.4472,6}, {0.8665,0.4721,8}, {0.8693,0.3504,9}, {0.8695,0.6505,10}, {0.8714,0.1753,9}, {0.8730,0.7287,6}, {0.8784,0.7440,9}, {0.8791,0.4043,6}, {0.8796,0.7647,9}, {0.8799,0.3611,9}, {0.8817,0.4368,10}, {0.8840,0.6679,10}, {0.8851,0.5556,15}, {0.8853,0.7114,15}, {0.8860,0.5292,10}, {0.8871,0.7189,12}, {0.8874,0.6939,12}, {0.8879,0.8477,6}, {0.8888,0.2031,6}, {0.8903,0.6100,9}, {0.8904,0.4065,10}, {0.8934,0.1369,15}, {0.8935,0.3755,10}, {0.8949,0.8920,12}, {0.8949,0.3788,9}, {0.8958,0.6313,8}, {0.8969,0.4690,10}, {0.8986,0.7533,10}, {0.9008,0.3919,12}, {0.9028,0.4074,6}, {0.9038,0.0701,9}, {0.9041,0.8962,9}, {0.9052,0.8266,8}, {0.9057,0.6597,15}, {0.9057,0.5549,9}, {0.9059,0.5964,10}, {0.9060,0.6425,15}, {0.9062,0.3165,12}, {0.9066,0.8396,6}, {0.9075,0.7739,12}, {0.9077,0.4104,6}, {0.9125,0.2924,12}, {0.9152,0.1945,15}, {0.9193,0.8590,6}, {0.9207,0.4982,10}, {0.9209,0.2803,8}, {0.9211,0.4229,12}, {0.9215,0.6408,15}, {0.9224,0.2391,12}, {0.9225,0.3167,6}, {0.9236,0.6843,15}, {0.9237,0.5344,6}, {0.9242,0.8233,9}, {0.9263,0.7206,9}, {0.9271,0.8169,15}, {0.9278,0.7097,9}, {0.9284,0.4568,10}, {0.9295,0.1652,9}, {0.9313,0.7585,12}, {0.9317,0.4923,6}, {0.9330,0.7902,10}, {0.9337,0.7749,12}, {0.9356,0.1391,12}, {0.9367,0.4999,15}, {0.9369,0.8245,10}, {0.9370,0.2584,10}, {0.9372,0.7650,8}, {0.9373,0.2569,8}, {0.9378,0.7396,12}, {0.9384,0.7793,6}, {0.9385,0.3203,6}, {0.9412,0.4993,12}, {0.9448,0.7460,9}, {0.9449,0.3498,12}, {0.9455,0.5602,12}, {0.9463,0.2395,8}, {0.9465,0.6679,10}, {0.9487,0.0479,6}, {0.9490,0.6309,10}, {0.9491,0.5676,15}, {0.9504,0.2149,6}, {0.9511,0.4245,9}, {0.9512,0.8678,9}, {0.9514,0.6367,8}, {0.9531,0.3174,6}, {0.9532,0.4579,8}, {0.9546,0.4121,6}, {0.9555,0.3192,10}, {0.9567,0.3354,6}, {0.9589,0.2069,10}, {0.9597,0.7351,12}, {0.9610,0.6560,8}, {0.9610,0.5212,12}, {0.9616,0.5845,12}, {0.9630,0.3681,10}, {0.9631,0.2582,15}, {0.9632,0.5523,8}, {0.9638,0.9188,10}, {0.9649,0.3824,9}, {0.9655,0.2486,9}, {0.9670,0.7745,15}, {0.9683,0.4664,8}, {0.9694,0.4495,9}, {0.9703,0.5182,10}, {0.9704,0.1765,15}, {0.9708,0.4490,12}, {0.9714,0.3193,9}, {0.9743,0.3883,9}, {0.9760,0.6300,15}, {0.9764,0.3853,9}, {0.9778,0.5354,9}, {0.9786,0.5709,10}, {0.9812,0.2899,12}, {0.9844,0.7581,10}, {0.9848,0.7404,12}, {0.9857,0.9313,9}, {0.9861,0.5313,15}, {0.9864,0.7463,12}, {0.9875,0.5099,6}, {0.9880,0.4192,12}, {0.9961,0.8194,15}, {0.9995,0.5381,15}, {0.9999,0.1357,12}}

-- phases
moonsprites = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}

skycolors =  {12, 0}
mooncolors = {6, 7}
starcolors = {12, 0}


-- old phases
--moonphases = {"new", "crescent", "first quarter", "gibbous", "full", "disseminating", "last quarter", "balsamic"}
--yearphases = { "summer", "autumn", "winter", "spring" }
--skyphases = { "twilight", "night", "midnight", "night", "twilight", "dawn", "morning", "noon", "afternoon", "evening", "dusk" }

-- times from timesz
-- 8736 year / 672 moon
-- days are simpler now
-- 364 / 28


-- new times ------------------
---- a pocketful of sand 2 ----
------ newtimes from timesz ---
-------- by @mzxio ------------


-- globals

-- time unit = days
uptime = (365.25/4)*33
speed = 1/720--1440--1/(24*60*60)

-- clocks
season = 0
day = 0
sunpos = 0

-- cloud colors
cloudbasecolor = 1
cloudshadcolor = 2


function _init()

	--cls()

	-- planets
	-- using synodic orbits
	planets = {}
	planets[1] = makebody(367.5, 1) -- neptune
	planets[2] = makebody(369.7, 12) -- uranus
	planets[3] = makebody(378.1, 10) -- saturn
	planets[4] = makebody(398.9, 9) -- jupiter
	planets[5] = makebody(779.9, 8) -- mars
	planets[6] = makebody(115.88, 5, 0.1) -- mercury
	planets[7] = makebody(583.9, 15, 0.2) -- venus
	planets["moon"] = makebody(29.531, 7)
	planets["sun"] = makebody(1, 7)

	-- stars
	stars = {}
	-- load stars from catalog
	for i = 1, #hyg do
		stars[i] = makebody(0.999,hyg[i][3],nil,hyg[i][1],hyg[i][2])
	end

	-- sky gradient
	skygrad = gradbase()

	-- clouds
	blobclouds = cloudbase()
	cirrusclouds = cloudbase()

end

function _update()

	-- clocks
	uptime = uptime + speed
	
	season = cos(moduloperiod(uptime,365.25))
	day = sin(-moduloperiod(uptime,1))

	-- sky gradient
	skygrad.colors = skyrules(day,sunpos)
	skygrad.grad = gradset(skygrad,skygrad.colors)
	
	-- clouds
	cloudshift(blobclouds)
	cloudshift(cirrusclouds)

end

function _draw()

	cls()

	-- sky
	graddraw(skygrad.grad)
	foreach(stars,stardraw)
	foreach(planets,planetdraw)
	moondraw(planets.moon)
	sundraw(planets.sun)

	-- clouds
	drawblobcloud(blobclouds)
	drawcirruscloud(cirrusclouds)

	-- surface
	--rectfill(0,84,127,127,1)
	circfill(64,312+88,320,2)
	circfill(74,312+91,320,1)

	-- debug	
	--print(uptime.." days",2,122,1)
	--print("uptime "..uptime,2,4,11)
	print("day "..day,2,121,9)
	--print("season "..season,2,22,11)

end

-- sky

-- data helpers

function makebody(period,spectra,maxangle,rightangle,declination)
	local body = {}
	body.p = period or 1
	body.c = spectra or 8
	body.ma = maxangle or nil
	body.ra = rightangle or 0
	body.dec = declination or 0.5
	return body
end

function findphase(tim, period, list)
	local query = moduloperiod(tim, period)
	local index = ceil(query * #list)
	return list[index]
end

-- drawing helpers

function skyform(theta, body, amp)
	local offsetx = 64
	local offsety = 76 + season * 12  
	local scale = 104 - season * 6
	local ra = body.ra
	local dec = body.dec
	local amp = amp or 1
	local vect = {}
	vect.x = offsetx + (cos(ra+theta) * dec) * scale * amp
	vect.y = offsety + (sin(ra+theta) * dec) * scale * amp
	return vect
end

function starform(theta, body)
	local offsetx = 64
	local offsety = 56 + season * 12  
	local scale = 180
	local centerx = 0.25--0.1054
	local centery = 0.48--0.9959
	local ra = body.ra
	local dec = body.dec
	local vect = {}
	vect.x = offsetx + ((ra - centerx) * cos(theta) * scale * 2) - ((dec - centery) * sin(theta) * scale)
	vect.y = offsety + ((ra - centerx) * sin(theta) * scale * 2) + ((dec - centery) * cos(theta) * scale)
	return vect
end

function skypose(body)
	-- time unit = days
	local theta = 0
	local orbit = moduloperiod(uptime,1)
	local offset = moduloperiod(uptime,body.p)
	-- limit orbit arc maxangle if needed
	if body.ma == nil then
		theta = orbit - offset
	else
		theta = orbit - sin(offset) * body.ma
	end
	local node = skyform(theta,body)
	return node
end

function stardraw(body)
	local offset = moduloperiod(uptime,body.p)
	local node = starform(offset,body,1.5)
	local starcol = findphase(uptime,1,starcolors)
	if starcol == 0 then
		pset(node.x,node.y,body.c)	
	else
		pset(node.x,node.y,starcol)
	end
end

function planetdraw(body)
	local node = skypose(body)
	local starcol = findphase(uptime,1,starcolors)
	if starcol == 0 then
			circfill(node.x,node.y,1,body.c)
	else
			circfill(node.x,node.y,1,starcol)
	end
	--pset(node.x,node.y,body.c)
end

function moondraw(body)
	local node = skypose(body)
	local datmoon = findphase(uptime,body.p,moonsprites)
	local skycol = findphase(uptime,1,skycolors)
	local mooncol = findphase(uptime,1,mooncolors)
	pal(5,skycol)	
	pal(7,mooncol)
	spr(datmoon,node.x-4,node.y-4)
end

function sundraw(body)
	local offset = moduloperiod(uptime,body.p)
	local node = skyform(offset,body)
	pal()
	spr(1,node.x-4,node.y-4)

	-- set sunpos global
	-- node divided by screenheight
	sunpos = node.y/128
end

-- gradients

-- init helper

function gradbase()
	local grad = {}
	grad.tl = vec(0,0)
	grad.br  = vec(128,128)
	grad.h = grad.br.y - grad.tl.y
	grad.grad = {}
	grad.colors = {}
	return grad
end

-- update helpers

function dither(a, b)
	-- values for comparison
	local vala = a or 1
	local valb = b or 2
	-- roll 3 randoms
	local r1 = vala --* rnd()
	local r2 = valb --* rnd() 
	local rx = (vala-valb) --* rnd()
	-- blur 0-?
	local bx = 1
	-- finish comparison
	if rx < (r2 - r1) * bx then
		return 0
	else
		return 1
	end
end

function gradtween(cols,row)	
	-- under, over
	local u,o = 0,1
	-- find place in gradient plan
	for y,p in pairs(cols) do
		if y < row and y > u then u = y end
		if y > row and y < o then o = y end
	end
	-- distance between under over
	local d1 = row - u
	local d2 = o - row
	-- dithering
	local x = dither(d1, d2)
	if x < 1 then
		return cols[u]
	else
		return cols[o]
	end
	-- fallback return
	--return 8
end


function skyrules(clock,angle)

	local ang = angle
 local colors = {}
	
	if clock >= 0 then
		-- day
		colors[ang - 0.2] = 1
		colors[ang] = 12
		colors[ang + 0.5] = 15
	elseif clock < 0 then
		-- night
		colors[ang - 0.2] = 0
		colors[ang] = 1
		colors[ang + 0.2] = 13
	end

	return colors

end

-- drawing helpers

function gradset(grad,cols)
	local table = {}
	-- default color
	local c = 0
		-- check every gradient row
	for i = 1, grad.h do
		local row = i / grad.h
		-- tween rows missing color
		if cols[row] == nil then
			c = gradtween(cols,row)
		else
			c = cols[row]
		end
		table[i] = c
	end
		return table	
end


function graddraw(table)
	for i = 1, #table do
		-- draw line
		local l = i --+ grad.tl.y
		circ(64,l+312,320,table[i])
	end
end

-- cloudy

-- init helpers

function cloudbase()
	local maxblobs = 10
	local blobrad = 5
	local cloudwidth = 128
	local cloudheight = 24
	local blobs = {}
	while #blobs <= maxblobs do
		local blob = cloudmaker(cloudwidth,cloudheight,blobrad)
		add(blobs, blob)
	end
	return blobs
end

function cloudmaker(cloudwidth,cloudheight,blobrad)
	local x = nrnd() * cloudwidth
	local y = nrnd() * cloudheight
	local r	= round(rnd() * blobrad)
	return vec3(x,y,r)
end

-- update helpers

function cloudshift(cloud)
	for i = 1, #cloud do
		cloud[i].x -= rnd()%rnd()
		if cloud[i].x + cloud[i].z <= 0 then
			local offset = 0 - cloud[i].x
			cloud[i].x = 128 + cloud[i].z - offset
		end
	end
end

-- drawing helpers

function drawblobcloud(cloud)
	local offsety = 48
	for i = 1, #cloud do
		local blob = cloud[i]
		-- shadow layer
		circfill(blob.x, offsety+blob.y, blob.z, cloudshadcolor)
		-- base layer
		circfill(blob.x-1, offsety+blob.y-1, blob.z, cloudbasecolor)
	end
end

function drawcirruscloud(cloud)
	local offsety = 24
	for i = 1, #cloud do
		local blob = cloud[i]
		-- shadow layer
		line(blob.x-(blob.z/2-1),offsety+blob.y+1,blob.x+(blob.z/2+1),offsety+blob.y+1,cloudshadcolor)
		-- base layer
		line(blob.x-(blob.z/2),offsety+blob.y,blob.x+(blob.z/2),offsety+blob.y,cloudbasecolor)
	end
end

-- mathy

function moduloperiod(t, p)
	return (t % p) / p
end

function vec3(x,y,z)
	local v = {}
	v.x = x
	v.y = y
	v.z = z
	return v
end

function nrnd()
	local x1,x2,rad,c = 0,0,0,0
	while rad >= 1 or rad == 0 do
		x1 = 2 * rnd() -1
		x2 = 2 * rnd() -1
		rad = (x1 * x1) + (x2 * x2)
	end
	c = sqrt(-2 * (rad * rad) / rad)
	return x1 * c
end

function round(n)
	local r = abs(n - flr(n))
	if r >= 0.5 then
		return ceil(n)
	else
		return flr(n)
	end
end

function tableprint(t)
	for k, v in pairs(t) do
		print(k..v)
	end
end

-- vector library

-- print vector
function vecprint(v)
	print("x = "..v.x..", y = "..v.y)
end

-- new vector
function vec(x,y)
	local v = {}
	v.x = x or 0
	v.y = y or 0
	return v
end
--vecprint(vec(1,2))

-- new vector from rad angle
function vecfromang(ang,mag)
	local mag = mag or 1
	return vec(cos(ang)*mag,sin(ang)*mag)
end
--vecprint(vecfromang(0.75))

-- vector length
function veclen(v)
	return sqrt((v.x * v.x) + (v.y * v.y))
end
--print(veclen(vec(3,2)))

-- vector to rad angle

function vecang(v)
	return atan2(v.x,v.y)
end
--print(vecang(vec(3,2)))

-- add vector b to a
function vecadd(a,b)
	local x = a.x + b.x
	local y = a.y + b.y
	return vec(x,y)
end
--vecprint(vecadd(vec(1,2),vec(1,2)))

-- subtract vector b from a
function vecsub(a,b)
	local x = a.x - b.x
	local y = a.y - b.y
	return vec(x,y)
end
--vecprint(vecsub(vec(2,4),vec(1,2)))

-- multiply vector a by b
function vecmult(a,b)
	local x = a.x * b.x
	local y = a.y * b.y
	return vec(x,y)
end
--vecprint(vecmult(vec(2,3),vec(6,4)))

-- divide vector a by b
function vecdiv(a,b)
	local x = a.x / b.x
	local y = a.y / b.y
	return vec(x,y)
end
--vecprint(vecdiv(vec(12,12),vec(2,3)))

-- normalize vector
function vecnorm(v)
	local l = veclen(v)
	local t = vec(l,l)
	return vecdiv(v,t)
end
--vecprint(vecnorm(vec(6,4)))

-- distance between vectors
function vecdist(a,b)
	local temp = vecsub(a,b)
	return veclen(temp)
end
--print(vecdist(vec(1,2),vec(6,4)))