//================================================================ // planet.cc // ÂÀÍ۷ϤÎÏÇÀ±¤Î°ÌÃÖ¤òÉÁ¤¯CGI // Copyright (C) Naoki Watanabe. 1995-1999. All rights reserved. //================================================================ #include #include #include #include #include "ppmgraph.h" const int IMG_WIDTH = 256; const int IMG_HEIGHT = 256; const int XC = IMG_WIDTH/2; const int YC = IMG_HEIGHT/2; const double MAG = 72.0; struct Planet { double r, omg, tho; // radius, anglur velocity, initial angle. char fname[32]; // file name of the PPM. //---- Calculate the position at the given time. void Position( time_t t, double& x, double& y ){ x = r*cos(omg*t+tho); y = r*sin(omg*t+tho); } }; // Radius is given in Astronomic unit (mean span between Sun and Earth). // Anglur velocity is given in rad/sec. // Initial angle is given in rad, which is the angle // at 00:00:00 on Jan 1, 2000. // Set data for Sun and four planets. Planet planets[5]= { { 0.000, 0.000e+00, 0.000, "planet0.ppm" }, // Sun { 0.387, 8.265e-07, 4.429, "planet1.ppm" }, // Mercury { 0.723, 3.236e-07, 3.145, "planet2.ppm" }, // Venus { 1.000, 1.991e-07, 1.737, "planet3.ppm" }, // Earth { 1.523, 1.058e-07, 0.021, "planet4.ppm" } // Mars }; //---- Calculate seconds since the intial time 00:00:00 on Jan 1, 2000. time_t GetTime( void ) { struct tm t2000; t2000.tm_sec = 0; t2000.tm_min = 0; t2000.tm_hour = 0; t2000.tm_mday = 1; t2000.tm_mon = 0; t2000.tm_year = 100; t2000.tm_wday = 0; t2000.tm_yday = 0; t2000.tm_isdst = 0; return time(NULL) - mktime(&t2000); } int main( void ) { double x, y; time_t t; Vram V(IMG_WIDTH, IMG_HEIGHT); t = GetTime(); for( int i=0; i<5; i++ ){ planets[i].Position( t, x, y ); // draw an orbit. V.DrawCircle( XC, YC, int(planets[i].r*MAG) ); // draw an image of the planet. V.PastePPM( XC-10+int(x*MAG), YC-10-int(y*MAG), planets[i].fname ); } return 0; }