1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export async function tidbytCircle({ size = 7, fill, border }: {
size?: number;
fill?: number;
border?: number;
}) {
const { default: Jimp } = await import("npm:jimp@0");
const img = await new Jimp(size, size);
for (const { x, y, idx, image } of img.scanIterator(0, 0, size, size)) {
const dx = x - size / 2 + 0.5;
const dy = y - size / 2 + 0.5;
const d = Math.sqrt(dx * dx + dy * dy);
if (d <= size / 2) {
if (typeof border === "number" && d > (size / 2 - 1)) {
image.setPixelColor(border, x, y);
}
else if (typeof fill === "number") {
image.setPixelColor(fill, x, y);
}
}
}
return img;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 12, 2024