#include #include double radius=100; void draw_point(double x, double y){ printf("
 
", radius+x*radius, radius+y*radius); } /* For simplicity, assume the circle to be drawn has center at (0,0) * and radius 1. `resolution' measures how far apart you want * points on the circle to be. It doesn't correspond to the actual distances, * but the maximum distance between consecutive points will be no * greater than the given resolution. */ void draw_circle (double resolution) { /* magic numbers */ const double x0 = -0.7373688781; const double y0 = -0.6754902943; const double r = 0.618033989; double x = 1; double y = 0; double res_got = 10.16640738; int a = 1; int b = 0; int c = 0; while (res_got > resolution) { a = a + b; b = a - b; for (; c < a; ++c) { double x_new = x*x0 - y*y0; draw_point(x, y); /* assume we have this function */ y = x*y0 + y*x0; x = x_new; } res_got *= r; } } int main(){ double res=0.010; char *cstr_queryString = getenv("QUERY_STRING"); if (cstr_queryString != NULL && strlen(cstr_queryString) > 0){ char *queryString = cstr_queryString; char *amp = NULL; do { amp = strchr(queryString, '&'); char *key, *value; if (amp != NULL){ *amp = '\0'; } //Break at the = sign. key = queryString; value = queryString; value = strchr(value, '='); if (value != NULL){ *value = '\0'; value++; } if (strcmp(key, "res") == 0){ res = strtod(value, NULL); } else if (strcmp(key, "rad") == 0){ radius = strtol(value, NULL, 10); } queryString = amp+1; } while (amp != NULL); } printf("Content-type: text/html\r\n\r\n"); printf("Lux Perpetua's draw_circle\n"); printf("\n"); printf("Radius: %f
Resolution: %f", radius, res); printf("
"); printf("
"); draw_circle(res); printf("
"); printf("http://forums.devshed.com/showpost.php?p=1364177&postcount=23\n"); return 0; }