1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { png } from "https://esm.town/v/andreterron/png";
export let hostpng_example = png({
width: 256,
height: 256,
}, (p) => {
const w = p.width, h = p.height;
// Create colors (red, green, blue, alpha)
const white = p.color(255, 255, 255, 255); // PNG starts filled with the first color
const black = p.color(0, 0, 0, 255);
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
// Get the buffer index for this position
let index = p.index(x, y);
// Set the color for the specific pixel
p.buffer[index] = (x * y) / (w * h) * 24 % 2 >= 1 ? black : white;
}
}
});