+/* returns the pixels. called many times. */
+static void
+pixack_frame(struct state *st, char *pix_buf)
+{
+ int i, j;
+ int w2 = st->width + 2;
+ unsigned short *t;
+#if test_pattern_hyper
+ if (st->frame&0x100)
+ sleep(1);
+#endif
+
+ if (!(st->frame%st->epoch_time)) {
+ int s;
+ if (0 != st->frame) {
+ int tt = st->epoch_time / 500;
+ if (tt > 15)
+ tt = 15;
+ /*sleep(tt);*/
+ }
+
+ for (i = 0; i < st->npix; i++) {
+ /* equilibrium */
+ st->r1[i] = 65500;
+ st->r2[i] = 11;
+ }
+
+ random_colors(st);
+
+ XSetWindowBackground(st->dpy, st->window, st->colors[255 % st->ncolors].pixel);
+ XClearWindow(st->dpy, st->window);
+
+ s = w2 * (st->height/2) + st->width/2;
+ st->radius = get_integer_resource (st->dpy, "radius", "Integer");
+ {
+ int maxr = st->width/2-2;
+ int maxr2 = st->height/2-2;
+ if (maxr2 < maxr) maxr = maxr2;
+
+ if (st->radius < 0)
+ st->radius = 1 + ((R%10) ? (R%5) : (R % maxr));
+ if (st->radius > maxr) st->radius = maxr;
+ }
+ for (i = -st->radius; i < (st->radius+1); i++)
+ for (j = -st->radius; j < (st->radius+1); j++)
+ st->r2[s + i + j*w2] = mx - (R&63);
+ st->reaction = get_integer_resource (st->dpy, "reaction", "Integer");
+ if (st->reaction < 0 || st->reaction > 2) st->reaction = R&1;
+ st->diffusion = get_integer_resource (st->dpy, "diffusion", "Integer");
+ if (st->diffusion < 0 || st->diffusion > 2)
+ st->diffusion = (R%5) ? ((R%3)?0:1) : 2;
+ if (2 == st->reaction && 2 == st->diffusion)
+ st->reaction = st->diffusion = 0;
+ }
+ for (i = 0; i <= st->width+1; i++) {
+ st->r1[i] = st->r1[i + w2 * st->height];
+ st->r2[i] = st->r2[i + w2 * st->height];
+ st->r1[i + w2 * (st->height + 1)] = st->r1[i + w2];
+ st->r2[i + w2 * (st->height + 1)] = st->r2[i + w2];
+ }
+ for (i = 0; i <= st->height+1; i++) {
+ st->r1[w2 * i] = st->r1[st->width + w2 * i];
+ st->r2[w2 * i] = st->r2[st->width + w2 * i];
+ st->r1[w2 * i + st->width + 1] = st->r1[w2 * i + 1];
+ st->r2[w2 * i + st->width + 1] = st->r2[w2 * i + 1];
+ }
+ for (i = 0; i < st->height; i++) {
+ int ii = i + 1;
+ char *q = pix_buf + st->width * i;
+ short *qq = ((short *) pix_buf) + st->width * i;
+/* long *qqq = ((long *) pix_buf) + st->width * i; -- crashes on Alpha */
+ int *qqq = ((int *) pix_buf) + st->width * i;
+ unsigned short *i1 = st->r1 + 1 + w2 * ii;
+ unsigned short *i2 = st->r2 + 1 + w2 * ii;
+ unsigned short *o1 = st->r1b + 1 + w2 * ii;
+ unsigned short *o2 = st->r2b + 1 + w2 * ii;
+ for (j = 0; j < st->width; j++) {
+#if test_pattern_hyper
+ int r1 = (i * j + (st->frame&127)*frame)&65535;
+#else
+ int uvv, r1 = 0, r2 = 0;
+ switch (st->diffusion) {
+ case 0:
+ r1 = i1[j] + i1[j+1] + i1[j-1] + i1[j+w2] + i1[j-w2];
+ r1 = r1 / 5;
+ r2 = (i2[j]<<3) + i2[j+1] + i2[j-1] + i2[j+w2] + i2[j-w2];
+ r2 = r2 / 12;
+ break;
+ case 1:
+ r1 = i1[j+1] + i1[j-1] + i1[j+w2] + i1[j-w2];
+ r1 = r1 >> 2;
+ r2 = (i2[j]<<2) + i2[j+1] + i2[j-1] + i2[j+w2] + i2[j-w2];
+ r2 = r2 >> 3;
+ break;
+ case 2:
+ r1 = (i1[j]<<1) + (i1[j+1]<<1) + (i1[j-1]<<1) + i1[j+w2] + i1[j-w2];
+ r1 = r1 >> 3;
+ r2 = (i2[j]<<2) + i2[j+1] + i2[j-1] + i2[j+w2] + i2[j-w2];
+ r2 = r2 >> 3;
+ break;
+ }