#include #include #include Rectangle canvas; Image *px; int dim, rad; void drawplane(float z, ulong c){ uchar abgr[4]; float x, y; Point p; int i, j; abgr[0] = c; abgr[1] = c >> 8; abgr[2] = c >> 16; abgr[3] = c >> 24; loadimage(px, px->r, abgr, 4); y = -2.f * z; for(i = 3; i < 9; i++){ x = -2.f * z; for(j = 3; j < 9; j++){ p.x = canvas.min.x + canvas.max.x + (int)(dim * x) >> 1; p.y = canvas.min.y + canvas.max.y - (int)(dim * y) >> 1; fillellipse(screen, p, rad, rad, px, ZP); x += z; } y += z; } } void main(int, char**){ float x, y, z; if(initdraw(nil, nil, "dot perspective") < 0) sysfatal("initdraw: %r"); px = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, 0xf0f4efff); if(px == nil) sysfatal("allocimage: %r"); canvas = screen->r; draw(screen, canvas, display->black, nil, ZP); if(Dx(canvas) < Dy(canvas)){ dim = Dx(canvas); canvas.min.y = canvas.min.y + canvas.max.y - dim >> 1; canvas.max.y = canvas.min.y + dim; }else{ dim = Dy(canvas); canvas.min.x = canvas.min.x + canvas.max.x - dim >> 1; canvas.max.x = canvas.min.x + dim; } rad = dim * .04; draw(screen, canvas, px, nil, ZP); drawplane(0.18f, setalpha(0xcccccccc, 160)); drawplane(0.2f, setalpha(0x283618ff, 160)); drawplane(0.22f, setalpha(0x606c38ff, 160)); drawplane(0.24f, setalpha(0xbc6c25ff, 160)); drawplane(0.26f, setalpha(0xdda15eff, 160)); flushimage(display, 1); sleep(9999990); exits(nil); }