+ Bool writable_p = False;
+ make_uniform_colormap (st->xgwa.screen, st->xgwa.visual,
+ st->xgwa.colormap, st->colors, &st->ncolors,
+ True, &writable_p, True);
+ }
+
+ if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height);
+
+ /* info is a structure holding all the random pieces of information I may want to
+ pass to my baby functions -- much of it I may never use, but it is nice to
+ have around just in case I want it to make a funky function funkier */
+/* info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */
+ st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float");
+ st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float");
+ st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float");
+ st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float");
+ st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float");
+ st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer");
+ st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer");
+ st->info->half_width = st->xgwa.width / 2;
+ st->info->half_height = st->xgwa.height / 2;
+ st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer");
+ st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer");
+ st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer");
+ st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float");
+ st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float");
+ st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode");
+ st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode");
+ st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean");
+ st->modifier = 3000.0 + frand(1500.0);
+ if (! st->xmode_str) st->xmode = spin_mode;
+ else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode;
+ else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode;
+ else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode;
+ else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode;
+ else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode;
+ else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode;
+ else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode;
+ else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode;
+ else {
+ st->xmode = random() % (int) lissajous_mode;
+ }
+ if (! st->ymode_str) st->ymode = spin_mode;
+ else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode;
+ else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode;
+ else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode;
+ else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode;
+ else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode;
+ else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode;
+ else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode;
+ else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode;
+ else {
+ st->ymode = random() % (int) lissajous_mode;
+ }
+
+ if (get_integer_resource(st->dpy, "start_time", "Integer") == -1)
+ st->current_time = (unsigned long int)(random());
+ else
+ st->current_time = get_integer_resource(st->dpy, "start_time", "Integer");
+ if (st->info->whirlies == -1)
+ st->info->whirlies = 1 + (random() % 15);
+ if (st->info->nlines == -1)
+ st->info->nlines = 1 + (random() % 5);
+ if (st->info->color_modifier == -1)
+ st->info->color_modifier = 1 + (random() % 25);
+ if (get_boolean_resource(st->dpy, "explain", "Integer"))
+ st->explaining = 1;
+ st->current_color = 1 + (random() % NCOLORS);
+
+ return st;
+}
+
+static unsigned long
+whirlygig_draw (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+ int wcount; /* wcount is a counter incremented for every whirly take note of
+ internal_time before you mess with it */
+ int change_time = 4000;
+
+ if (st->explaining == 1) {
+ XClearWindow (st->dpy, st->window);
+ draw_explain_string(st, st->xmode, st->info->half_height-100,
+ st->dpy, st->window, st->fgc);
+ st->explaining++;
+ return 3000000;
+ } else if (st->explaining == 2) {
+ XClearWindow (st->dpy, st->window);
+ st->explaining = 0;
+ }
+
+ if (! strcmp (st->xmode_str, "change") && ! strcmp (st->ymode_str, "change")) {
+ if ((st->current_time - st->start_time) > change_time) {
+ st->start_time = st->current_time;
+ st->xmode = 1 + (random() % 4);
+ st->ymode = 1 + (random() % 4);
+ }
+ }
+ else if (! strcmp (st->xmode_str, "change")) {
+ if ((st->current_time - st->start_time) > change_time) {
+ st->start_time = st->current_time;
+ st->xmode = 1 + (random() % 4);
+ }
+ }
+ else if (! strcmp (st->ymode_str, "change")) {
+ if ((st->current_time - st->start_time) > change_time) {
+ st->start_time = st->current_time;
+ st->ymode = 1 + (random() % 3);
+ printf("Changing ymode to %d\n", st->ymode);
+ }
+ }
+ if (++st->current_color >= NCOLORS)
+ st->current_color = 0;
+ for (wcount = 0; wcount < st->info->whirlies; wcount++) {
+ int lcount; /* lcount is a counter for every line -- take note of the offsets changing */
+ int internal_time = 0;
+ int color_offset = (st->current_color + (st->info->color_modifier * wcount)) % NCOLORS;
+ if (st->current_time != 0)
+ /* I want the distance between whirlies to increase more each whirly */
+ internal_time = st->current_time + (10 * wcount) + (wcount * wcount);
+ switch (st->xmode) {
+ /* All these functions expect an int time, the struct info,
+ a pointer to an array of positions, and the index that the
+ the function will fill of the array */
+ case spin_mode:
+ spin(st, internal_time, st->info, st->pos, 0);
+ break;
+ case funky_mode:
+ funky(st, internal_time, st->info, st->pos, 0);
+ break;
+ case circle_mode:
+ circle(st, internal_time, st->info, st->pos, 0);
+ break;
+ case linear_mode:
+ linear(st, internal_time, st->info, st->pos, 0);
+ break;
+ case fun_mode:
+ fun(st, internal_time, st->info, st->pos, 0);
+ break;
+ case test_mode:
+ test(st, internal_time, st->info, st->pos, 0);
+ break;
+ case innie_mode:
+ innie(st, internal_time, st->info, st->pos, 0, st->modifier);
+ break;
+ case lissajous_mode:
+ lissajous(st, internal_time, st->info, st->pos, 0);
+ break;
+ default:
+ spin(st, internal_time, st->info, st->pos, 0);
+ break;
+ } /* End of the switch for the x position*/
+ switch (st->ymode) {
+ case spin_mode:
+ spin(st, internal_time, st->info, st->pos, 1);
+ break;
+ case funky_mode:
+ funky(st, internal_time, st->info, st->pos, 1);
+ break;
+ case circle_mode:
+ circle(st, internal_time, st->info, st->pos, 1);
+ break;
+ case linear_mode:
+ linear(st, internal_time, st->info, st->pos, 1);
+ break;
+ case fun_mode:
+ fun(st, internal_time, st->info, st->pos, 1);
+ break;
+ case test_mode:
+ test(st, internal_time, st->info, st->pos, 1);
+ break;
+ case innie_mode:
+ innie(st, internal_time, st->info, st->pos, 1, st->modifier);
+ break;
+ case lissajous_mode:
+ lissajous(st, internal_time, st->info, st->pos, 1);
+ break;
+ default:
+ spin(st, internal_time, st->info, st->pos, 1);
+ break;
+ } /* End of the switch for the y position*/
+ for (lcount = 0; lcount < st->info->nlines; lcount++) {
+ double arg = (double)((internal_time * st->info->offset_period) / 90.0);
+ double line_offset = 20.0 * (double)lcount * sin(arg);
+ int size;
+ size = (int)(15.0 + 5.0 * sin((double)internal_time / 180.0));
+ /* First delete the old circle... */
+ if (!st->info->trail
+#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
+ && ( !st->dbeclear_p || !st->backb)
+#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
+ ) {
+ XSetForeground(st->dpy, st->bgc, BlackPixel(st->dpy, st->screen));
+ XFillArc(st->dpy, st->b, st->bgc, st->last_x[wcount][lcount], st->last_y[wcount][lcount], st->last_size[wcount][lcount], st->last_size[wcount][lcount], START_ARC, END_ARC);
+ }
+ /* Now, lets draw in the new circle */
+ { /* Starting new scope for local x_pos and y_pos */
+ int xpos, ypos;
+ if (st->wrap) {
+ xpos = preen((int)(st->info->xoffset*line_offset)+st->pos[0], st->info->half_width * 2);
+ ypos = preen((int)(st->info->yoffset*line_offset)+st->pos[1], st->info->half_height * 2);