static void * petri_init (Display *dpy, Window win) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = win; st->delay = get_integer_resource (st->dpy, "delay", "Delay"); st->orthlim = 1; setup_display (st); setup_arr (st); randblip (st, 1); return st; }
static void update (struct state *st) { cell *a; for (a = st->head->next; a != st->tail; a = a->next) { static const XPoint all_coords[] = {{-1, -1}, {-1, 1}, {1, -1}, {1, 1}, {-1, 0}, { 1, 0}, {0, -1}, {0, 1}, {99, 99}}; const XPoint *coords = 0; if (a->speed == 0) continue; a->growth += a->speed; if (a->growth >= st->diaglim) { coords = all_coords; } else if (a->growth >= st->orthlim) { coords = &all_coords[4]; } else { continue; } while (coords->x != 99) { int x = cell_x(a) + coords->x; int y = cell_y(a) + coords->y; coords++; if (x < 0) x = st->arr_width - 1; else if (x >= st->arr_width) x = 0; if (y < 0) y = st->arr_height - 1; else if (y >= st->arr_height) y = 0; newcell (st, &st->arr[y * st->arr_width + x], a->col, a->speed); } if (a->growth >= st->diaglim) killcell (st, a); } randblip (st, (st->head->next) == st->tail); for (a = st->head->next; a != st->tail; a = a->next) { if (a->isnext) { a->isnext = 0; a->speed = a->nextspeed; a->growth = 0.0; a->col = a->nextcol; drawblock (st, cell_x(a), cell_y(a), a->col + st->count); } } }