/* draw random rectangles in the current window * sort of like the xscreensaver we all know * -- andrey */ /* based on russ cox' click.c */ #include #include #include #include #include int minx, miny, maxx, maxy; void eresized(int new) { Rectangle r; if(new && getwindow(display, Refnone) < 0) fprint(2,"can't reattach to window"); r = screen->r; minx = r.min.x; miny = r.min.y; maxx = r.max.x; maxy = r.max.y; draw(screen, screen->r, display->white, nil, ZP); } void main(int argc, char **argv) { Mouse m; Image *img; Rectangle r; int i; int slp = 10; char *items[] = { "slower", "faster", "exit", nil }; Menu menu; /* setup menus */ menu.item = items; menu.gen = nil; srand(0); initdraw(0,0,"whoopty doo"); eresized(0); einit(Emouse); for(;;){ if(ecanmouse()) { m = emouse(); if(m.buttons & 4) { switch(emenuhit(3, &m, &menu)) { case 0: slp += 10; break; case 1: if(slp) slp -= 10; else slp = 0; break; case 2: exits("user abort"); default: fprint(2, "impossible button\n"); } } } /* draw a rectangle somewhere in the window */ /* make sure rectangle does not overflow window */ r.min.x = minx + nrand(maxx - minx); r.min.y = miny + nrand(maxy - miny); r.max.x = r.min.x + nrand(maxx - r.min.x); r.max.y = r.min.y + nrand(maxy - r.min.y); /* get a random color and random alpha for drawing */ /*** probably not the best way of doing it ***/ img = allocimagemix(display,nrand(256)<<24 | nrand(256) << 16 | nrand(256) <<8 | (256 - nrand(256)),nrand(256)<<24 | nrand(256) << 16 | nrand(256) <<8 | (256 - nrand(256))); draw(screen, r, img, nil, ZP); flushimage(display, 1); freeimage(img); /* slow down the drawing somehow */ sleep(slp); } }