#include #include #include #include #define RGBA rgba #define MIN(a,b) ((a)<(b)?(a):(b)) int rgba(int r, int g, int b, int a) { int c; r = (r*a)/255; g = (g*a)/255; b = (b*a)/255; c= (r<<24) | (g<<16) | (b<<8) | (a); return c; } enum { Nbg = 3 }; Image *fg[2][2][3]; Image *bg[Nbg]; void main(int argc, char *argv[]) { Event e; Rectangle r1 = Rect(0,0,1,1); Image **i; USED(argc, argv); if (initdraw(nil, nil, "blend") < 0) { fprint(2, "initdraw failed: %r\n"); exits("initdraw"); } einit(Emouse|Ekeyboard); bg[0] = allocimage(display, r1, RGBA32, 1, DBlack); bg[1] = allocimage(display, r1, RGBA32, 1, DWhite); bg[2] = allocimage(display, r1, RGBA32, 1, RGBA(0,0,0,64)); // Pure CMY i = fg[0][0]; *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,255,0,255)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,255,255,255)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,0,255,255)); // 50% CMY i = fg[0][1]; *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,255,0,127)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,255,255,127)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,0,255,127)); // Pure RGB i = fg[1][0]; *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,0,0,255)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,255,0,255)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,0,255,255)); // 50% RGB i = fg[1][1]; *i++ = allocimage(display, r1, RGBA32, 1, RGBA(255,0,0,127)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,255,0,127)); *i++ = allocimage(display, r1, RGBA32, 1, RGBA(0,0,255,127)); eresized(0); for (;;) { switch(event(&e)){ case Ekeyboard: switch(e.kbdc){ case 'q': case '\04': exits(nil); } break; case Emouse: if(e.mouse.buttons){ } break; } } exits(nil); } void spots(Point o, int R, Image *bg, Image **fg) { Rectangle r = Rpt(o, addpt(o, Pt(3*R, 3*R))); draw(screen, r, bg, nil, ZP); fillellipse(screen, addpt(o,Pt(1*R,2*R)), R,R, fg[0], ZP); fillellipse(screen, addpt(o,Pt(2*R,2*R)), R,R, fg[1], ZP); fillellipse(screen, addpt(o,Pt(1.5*R,1*R)), R,R, fg[2], ZP); } void redraw(Image *screen) { Rectangle r = screen->r; int dX = r.max.x-r.min.x; int dY = r.max.y-r.min.y; int R = MIN(dX,dY)/4/3; int x, y; fprint(2, "s=%R, R=%d\n", screen->r, R); // draw(screen, r, bg[2], nil, ZP); for (x=0; x<4; ++x) for (y=0; y<4; ++y) spots(addpt(r.min, Pt(x*3*R, y*3*R)), R, bg[(x<2)+(y<2)], fg[y%2][x%2]); //flushimage(display, 1); } void eresized(int new) { if(new && getwindow(display, Refnone) < 0){ fprint(2, "can't reattach to window: %r\n"); exits("attach"); } redraw(screen); }