/* moonage.c - Don Yang (uguu.org) Ported from moonage.pl 07/10/03 */ #include #include #include #include #define SYN 29.530588853 #define AGE1 23.686 #define W 48 #define H 32 #define PI 3.14159265358979323846264338327950288419716939937510 static double MoonAge(void) { time_t t; struct tm *g; double d; int y; t = time(NULL); g = gmtime(&t); assert(g != NULL); y = g->tm_year - 100; d = (double)(g->tm_yday + y * 365. + (int)((y + 3) / 4) + (int)((y - 1) / 100) + (int)((y - 1) / 400)) + (g->tm_hour + (g->tm_min + g->tm_sec / 60.) / 60.) / 24.; return fmod(d + AGE1, SYN); } static void Render(double phase) { static const char dict1[65] = " `'\" `'\" `'\"+++\",;:8,(|7+888+<89.::8+|88.8)P+8>P.888,d8).8b(odb8"; static const char dict2[65] = " `'\"-`'\" ''\"-'`\",:::,:::.:::.:::.:::,:::.:::,:::.:::,:::.:::.:::"; static const int vx[6] = {1, 0, 1, 0, 1, 0}; static const int vy[6] = {0, 0, 1, 1, 2, 2}; static int grid[W * 2 + 2][H * 2 + 2]; unsigned int i, x1, x2; double s, l, r; int x, y, g; for(y = -H; y <= H; y++) { s = W * sqrt(1 - (double)(y * y) / (H * H)); if( phase < SYN / 2 ) { l = s * (1 - 4 * (phase / SYN)); r = s; } else { l = s * -1.0; r = s * (3 - 4 * (phase / SYN)); } for(x = -W; x <= W; x++) { grid[x + W + 1][y + H + 1] = ((double)x >= l && (double)x <= r) ? 1 : 0; } for(x = 0; x < 256; x++) { if( grid[(int)(W * cos(x * PI / 128.0)) + W + 1] [(int)(H * sin(x * PI / 128.0)) + H + 1] == 0 ) grid[(int)(W * cos(x * PI / 128.0)) + W + 1] [(int)(H * sin(x * PI / 128.0)) + H + 1] = 2; } } for(y = -H; y < H; y += 3) { for(x = -W; x < W; x += 2) { for(i = x1 = x2 = 0; i < 6; i++) { g = grid[x + vx[i] + W + 1][y + vy[i] + H + 1]; if( g == 1 ) x1 += (1 << i); if( g == 2 ) x2 += (1 << i); } if( dict1[x1] == ' ' ) (void)putchar((int)dict2[x2]); else (void)putchar(dict1[x1]); } (void)putchar('\n'); } } int main(void) { Render(MoonAge()); return 0; }