/* * Header Begins--Do not remove################################################ * * C-code to compute a trochoid as in p 32 of the book * * (c) Eugene Fiume, University of Toronto, 1995. * * You are permitted to use this code for noncommercial, educational * purposes only. This header must not be removed from this file. * * Header Ends--Do not remove################################################## */ #include #include #define RADIUS 100 #define OFFSET 200 #define XRES 800 #define YRES 400 #define PI 3.141593 #define round(x) ( (int)( (x)+0.5 ) ) main(argc, argv) int argc; char *argv[]; { double x,y; int i,s,xn,yn; double u, r, a, du; printf("A Trochoid.\n\n"); XOpen(XRES,YRES, argc, argv); printf("Hit a mouse button to start.\n"); GetEvent(); r = RADIUS; a = 25; du = 0.01; u = 0; x = 0; y = RADIUS; /* * Now let's draw the trochoid. */ while(u < 9*PI) { xn = round(x); yn = round(y); setpixel(xn,YRES-(OFFSET+yn),1); /* X is upsidedown */ u += du; x = a*u - r*sin(u); y = r*cos(u); } printf("Hit a mouse button to end.\n"); GetEvent(); }