#include #include #include typedef double Num; Num zoom; int width; int height; const char *title; Num a; int doit = 1; int try_to_die = 0; // _shapes_ ---------------------------------------------------------- // max number of pixels error Num angle_per_radian = 180 / M_PI; Num arc_max_error = 0.25; Num a_pixel = 1; void draw_arc(Num x0, Num y0, Num x1, Num y1, Num angle) { angle /= angle_per_radian; // TODO simplify, use GL rotate / scale / translate Num dx, dy, d, hf, ox, oy, r, da, x, y, s, c, x_, y_, altx, alty, alt; Num bend = 1; angle = -angle; dx = (x1 - x0)/2; dy = (y1 - y0)/2; d = hypot(dx, dy); // calc origin hf = 1 / tan(angle / 2); ox = x0 + dx + dy*hf * bend; oy = y0 + dy - dx*hf * bend; // radius r = d / sin(fabs(angle)/2); da = acos(1 - arc_max_error * a_pixel / r) * 2; altx = dy * hf; alty = -dx * hf; alt = hypot(altx, alty); altx /= alt; alty /= alt; if (try_to_die) { printf("glVertex2d(%f, %f);\n", x0, y0); if (doit) glVertex2d(x0, y0); } int steps = fabs(angle) / da; for(int i=0; i\n" "#include \n" "#include \n" "typedef double Num;\n" "Num zoom;\n" "int width;\n" "int height;\n" "const char *title;\n" "\n" "int main(int argc, char *argv[]) {\n" " glutInit(&argc,argv);\n" " glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);\n" " \n" " title = \"AMPS\";\n" " \n" " glutCreateWindow(title);\n" " width = glutGet(GLUT_WINDOW_WIDTH);\n" " height = glutGet(GLUT_WINDOW_HEIGHT);\n" " \n" " gluOrtho2D(-width/2, width/2, -height/2, height/2);\n" "\n" ); if (doit) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); } title = "AMPS"; if (argc >= 2) a = atof(argv[1]); a = random()*1.0 / RAND_MAX * 20; fprintf(stderr, "%f\n", a); if (doit) { glutCreateWindow(title); width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); } if (doit) gluOrtho2D(-width/2, width/2, -height/2, height/2); display(); printf( " glutMainLoop();\n" " return 0;\n" "}\n" ); if (doit) glutMainLoop(); return 0; }