#include #include #include #include int size=50; // Returns random number 1 to 49 int ball (void) { return 1 + rand () % 49; } // show a ball in svg void showball (int pos, int num) { char *col; if (num < 10) col = "white"; else if (num < 20) col = "blue"; else if (num < 30) col = "red"; else if (num < 40) col = "green"; else col = "yellow"; printf ("\n", size + pos * 2 * size, size, size * 9 / 10, col); printf ("%02d\n", size + pos * 2 * size, size * 135 / 100, size, num); } void makegradient (char *col, char *col1, char *col2) { printf ("\n" "\n" "\n", col, col1, col2); } int main (int argc, const char *argv[]) { char c; int b1, b2, b3, b4, b5, b6, b7; poptContext optCon; struct poptOption optionsTable[] = { {"ball-size", 'b', POPT_ARG_INT, &size, 0, "Ball Size", "pixels"}, POPT_AUTOHELP {NULL, 0, 0, NULL, 0} }; optCon = poptGetContext (NULL, argc, argv, optionsTable, 0); if ((c = poptGetNextOpt (optCon)) < -1) { fprintf (stderr, "%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c)); return 1; } if (poptPeekArg (optCon)) { poptPrintUsage (optCon, stderr, 0); return 1; } srand (time (0)); b1 = ball (); do b2 = ball (); while (b2 == b1); do b3 = ball (); while (b3 == b2 || b3 == b1); do b4 = ball (); while (b4 == b3 || b4 == b2 || b4 == b1); do b5 = ball (); while (b5 == b4 || b5 == b3 || b5 == b2 || b5 == b1); do b6 = ball (); while (b6 == b5 || b6 == b4 || b6 == b3 || b6 == b2 || b6 == b1); do b7 = ball (); while (b7 == b6 || b7 == b5 || b7 == b4 || b7 == b3 || b7 == b2 || b7 == b1); printf ("Content-Type: image/svg+xml\n\n"); printf ("\n" "\n" "\n" "\n"); makegradient ("white", "white", "#CCCCCC"); makegradient ("red", "white", "red"); makegradient ("blue", "white", "blue"); makegradient ("green", "white", "green"); makegradient ("yellow", "white", "yellow"); printf ("\n"); showball (0, b1); showball (1, b2); showball (2, b3); showball (3, b4); showball (4, b5); showball (5, b6); showball (7, b7); printf ("\n"); return 0; }