SPB Git
895 B · 12 lines typescript
1import { PNG } from "pngjs";2import fs from "node:fs";3const W = 400, H = 300;4const png = new PNG({ width: W, height: H });5for (let i = 0; i < W * H * 4; i += 4) { png.data[i] = 255; png.data[i+1] = 255; png.data[i+2] = 255; png.data[i+3] = 255; }6function set(x: number, y: number, r: number, g: number, b: number) { const i = (W * y + x) * 4; png.data[i] = r; png.data[i+1] = g; png.data[i+2] = b; }7function circle(cx: number, cy: number, rad: number) { for (let y = 0; y < H; y++) for (let x = 0; x < W; x++) if ((x-cx)**2 + (y-cy)**2 <= rad*rad) set(x, y, 220, 30, 30); }8function square(x0: number, y0: number, s: number) { for (let y = y0; y < y0+s; y++) for (let x = x0; x < x0+s; x++) set(x, y, 30, 60, 220); }9circle(70, 80, 40); circle(200, 80, 40); circle(330, 80, 40); square(150, 170, 100);10fs.writeFileSync("benchmarks/vision-test.png", PNG.sync.write(png));11console.log("ok");12
Files · 66af8bfc031fad4ebd89e721b6d66962e2525f4d
Menu

Theme