/* ^echo w; window -r 0 0 699 699 -cd src rci '''mk 6.brush && 6.brush''' */ #include #include #include Image *px; uchar abgr[4] = {30, 30, 20, 30}; Point o[65]; void spray(Point c, int rad, int n){ int x, y, r; double θ; while(n--){ r = sqrt(frand()) * rad; θ = frand() * 2.0 * PI; x = c.x + r * cos(θ); y = c.y + r * sin(θ); draw(screen, Rect(x, y, x + 1, y + 1), px, nil, ZP); } } void stroke(Point from, Point to){ int steps; steps = 8; while(steps){ spray(from, 16, 200); from.x += (to.x - from.x) / steps; from.y += (to.y - from.y) / steps; --steps; } } void chaikin(int n){ Point p, ¼; int i; p = o[0]; for(i = n; i < 64; i += n + n){ ¼ = divpt(subpt(o[i + n], p), 4); o[i] = addpt(p, ¼); p = o[i + n]; o[i + n] = subpt(p, ¼); } } void main(int, char**){ int i, r; double θ; i = truerand(); print("%d", i); srand(i); if(initdraw(nil, nil, nil) < 0) sysfatal("initdraw: %r"); px = allocimage(display, Rect(0, 0, 1, 1), RGBA32, 1, DNofill); if(px == nil) sysfatal("allocimage: %r"); draw(screen, screen->r, display->black, nil, ZP); loadimage(px, px->r, abgr, 4); r = 196; o[0] = Pt(screen->r.min.x + screen->r.max.x >> 1, screen->r.min.y + screen->r.max.y >> 1); θ = 0.0; while(9){ for(i = 8; i <= 64; i += 8){ θ += PIO2 + frand() * PIO2 - PIO2 / 2; o[i] = addpt(o[i - 8], Pt(r * cos(θ), r * sin(θ))); // o[i].x = o[i - 8].x + r; // o[i].y = o[0].y + nrand(r) - r / 2; } chaikin(4); chaikin(2); chaikin(1); for(i = 0; i < 64; i++){ stroke(o[i], o[i + 1]); flushimage(display, 1); // sleep(10); } o[0] = o[64]; if(o[0].x < screen->r.min.x) o[0].x = screen->r.max.x; if(o[0].y < screen->r.min.y) o[0].y = screen->r.max.y; if(o[0].x >= screen->r.max.x) o[0].x = screen->r.min.x; if(o[0].y >= screen->r.max.y) o[0].y = screen->r.min.y; } }