#include #include #include Image *px; void drawbox(int i, int c){ Rectangle r; uchar bgr[3]; r.min = addpt(screen->r.min, Pt(i << 3 & 0x1f8, i >> 3 & 0x1f8)); r = rectaddpt(Rect(0, 0, 8, 8), r.min); bgr[0] = c << 4 & 0xf0; bgr[1] = c & 0xf0; bgr[2] = c >> 4 & 0xf0; loadimage(px, px->r, bgr, 3); draw(screen, r, px, nil, ZP); } int cmp2; int cmp2d(int *p1, int *p2){ int x, y, d1, d2; x = (*p1 >> 6) - (cmp2 >> 6); y = (*p1 & 0x3f) - (cmp2 & 0x3f); d1 = x * x + y * y; x = (*p2 >> 6) - (cmp2 >> 6); y = (*p2 & 0x3f) - (cmp2 & 0x3f); d2 = x * x + y * y; return d1 - d2; } int cmp3; int cmp3d(int *p1, int *p2){ int r, g, b, d1, d2; r = (*p1 >> 8) - (cmp3 >> 8); g = (*p1 >> 4 & 15) - (cmp3 >> 4 & 15); b = (*p1 & 15) - (cmp3 & 15); d1 = r * r + g * g + b * b; r = (*p2 >> 8) - (cmp3 >> 8); g = (*p2 >> 4 & 15) - (cmp3 >> 4 & 15); b = (*p2 & 15) - (cmp3 & 15); d2 = r * r + g * g + b * b; return d1 - d2; } void main(int, char**){ int sq[4096], hue[4096], i; ulong seed; seed = truerand(); print("0x%u.8x\n", seed); srand(seed); if(initdraw(nil, nil, "smoke") < 0) sysfatal("initdraw: %r"); px = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, DNofill); if(px == nil) sysfatal("allocimage: %r"); draw(screen, screen->r, display->black, nil, ZP); for(i = 0; i < 4096; i++) sq[i] = hue[i] = i; i = lrand() & 4095; sq[0] = sq[i]; sq[i] = 0; i = lrand() & 4095; hue[0] = hue[i]; hue[i] = 0; for(i = 0; i < 4096; i++){ drawbox(cmp2 = sq[i], cmp3 = hue[i]); qsort(sq + i + 1, 4095 - i, sizeof *sq, cmp2d); qsort(hue + i + 1, 4095 - i, sizeof *hue, cmp3d); flushimage(display, 1); sleep(3); } flushimage(display, 1); sleep(99999999); exits(nil); }