+ 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);