File size: 20,391 Bytes
e46f6f7 018f164 78b2882 c8a6842 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | 'use strict';
const test = require('node:test');
const assert = require('node:assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const pixel = require('../server/pixel');
const quota = require('../server/gemini-quota');
function tmpDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'pixel-test-'));
}
function opaqueColors(canvas) {
const out = new Set();
for (const v of canvas.data) if (v) out.add(canvas.palette[v - 1]);
return out;
}
test('pixel: drawing stays inside the palette, alpha is all-or-nothing', () => {
const canvas = new pixel.Canvas(32, 32, pixel.resolvePalette('pico8'));
const p = new pixel.Painter(canvas);
p.apply({ op: 'circle', cx: 16, cy: 16, r: 10, color: '#ff004d' });
p.apply({ op: 'noise', colors: ['#ffa300', '#123456'], density: 0.3, seed: 2, only: 'opaque' });
p.apply({ op: 'outline', color: 0 });
assert.ok([...p.warnings].some((w) => w.includes('#123456')), 'off-palette colour is reported');
for (const c of opaqueColors(canvas)) assert.ok(canvas.palette.includes(c));
const rgba = pixel.render(canvas, { scale: 1 });
for (let i = 3; i < rgba.length; i += 4) assert.ok(rgba[i] === 0 || rgba[i] === 255);
// noise with only:"opaque" never paints outside the circle
assert.strictEqual(canvas.get(0, 0), 0);
});
test('pixel: grid op, symmetry and failed batches', () => {
const dir = tmpDir();
const canvas = new pixel.Canvas(8, 4, pixel.resolvePalette(['#000000', '#ffffff']));
const p = new pixel.Painter(canvas, { cwd: dir, symmetry: 'x' });
p.apply({ op: 'grid', rows: ['ab..', '.a..'], legend: { a: '#000000', b: '#ffffff' } });
assert.strictEqual(canvas.get(0, 0), 1);
assert.strictEqual(canvas.get(7, 0), 1, 'mirrored across x');
assert.strictEqual(canvas.get(6, 0), 2);
assert.throws(() => p.apply({ op: 'grid', rows: ['z'], legend: {} }), /legend/);
assert.throws(() => p.apply({ op: 'nope' }), /Bilinmeyen/);
});
test('pixel: save/load round trip writes a valid PNG', () => {
const dir = tmpDir();
const canvas = new pixel.Canvas(5, 3, pixel.resolvePalette('gameboy'));
new pixel.Painter(canvas).apply({ op: 'rect', x: 1, y: 1, w: 3, h: 1, color: '#9bbc0f' });
const png = pixel.save(dir, 'demo', canvas);
const back = pixel.load(dir, 'demo');
assert.deepStrictEqual([...back.data], [...canvas.data]);
const img = pixel.decodeImage(fs.readFileSync(png));
assert.strictEqual(img.w, 5);
assert.strictEqual(img.data[(1 * 5 + 1) * 4 + 3], 255);
assert.strictEqual(img.data[3], 0);
assert.deepStrictEqual(pixel.list(dir).map((c) => c.name), ['demo']);
assert.throws(() => pixel.load(dir, '../x'), /name/);
});
test('pixel: autotile sheet and map with base ground', () => {
const dir = tmpDir();
const pal = pixel.resolvePalette('endesga32');
const grass = new pixel.Canvas(8, 8, pal);
grass.data.fill(pal.indexOf('#3e8948') + 1);
pixel.save(dir, 'grass', grass);
const water = new pixel.Canvas(8, 8, pal);
water.data.fill(pal.indexOf('#0099db') + 1);
pixel.save(dir, 'water', water);
const sheet = pixel.buildTileset(water);
assert.strictEqual(sheet.w, 32);
// variant 0 (no exposed side) is the tile itself; variant 15 has cut corners
assert.strictEqual(sheet.get(0, 0), water.get(0, 0));
assert.strictEqual(sheet.get(24, 24), 0);
pixel.save(dir, 'water_auto', sheet);
const map = pixel.buildMap(dir, { rows: ['gwg'], tiles: { g: 'grass' }, autotile: { w: 'water_auto' }, base: 'grass' });
assert.strictEqual(map.w, 24);
assert.ok(!map.data.includes(0), 'base ground fills the cut corners');
});
test('pixel: pixelize removes a key background and keeps a crisp silhouette', () => {
const w = 64;
const data = new Uint8Array(w * w * 4);
for (let y = 0; y < w; y++) {
for (let x = 0; x < w; x++) {
const i = (y * w + x) * 4;
const inside = x >= 16 && x < 48 && y >= 16 && y < 48;
data.set(inside ? [200, 30, 40, 255] : [255, 0, 255, 255], i);
}
}
const canvas = pixel.pixelize({ w, h: w, data }, { width: 8, palette: 'endesga32', background: '#ff00ff', outline: '#181425' });
assert.strictEqual(canvas.w, 8, 'requested size, outline included');
assert.strictEqual(canvas.palette[canvas.get(0, 3) - 1], '#181425', 'outline on the left edge');
assert.strictEqual(canvas.get(0, 0), 0, 'outline corners stay clean');
const colors = opaqueColors(canvas);
assert.ok(colors.has('#181425'));
assert.ok(colors.size <= 2);
assert.strictEqual(pixel.imageType(pixel.encodePNG(1, 1, new Uint8Array(4))), 'png');
});
test('gemini quota: pools and image model are summarised', () => {
const q = quota.summarize({
models: {
'gemini-3-flash': { displayName: 'Gemini 3 Flash', modelProvider: 'MODEL_PROVIDER_GOOGLE', quotaInfo: { remainingFraction: 0.8, resetTime: '2026-11-06T18:00:00Z' } },
'gemini-3.1-flash-image': { displayName: 'Image', modelProvider: 'MODEL_PROVIDER_GOOGLE', quotaInfo: { remainingFraction: 0.7, resetTime: '2026-11-06T18:00:00Z' } },
'claude-x': { displayName: 'Claude', modelProvider: 'MODEL_PROVIDER_ANTHROPIC', quotaInfo: { remainingFraction: 1 } },
internal: { modelProvider: 'MODEL_PROVIDER_GOOGLE', quotaInfo: { remainingFraction: 0 } },
},
imageGenerationModelIds: ['gemini-3.1-flash-image'],
});
assert.strictEqual(q.pools[0].key, 'gemini');
assert.strictEqual(q.pools[0].remaining, 0.7);
assert.strictEqual(q.image.remaining, 0.7);
assert.match(quota.formatQuota({ ok: true, ...q }), /Görsel üretimi/);
});
test('pixel: leaves brush stays on the silhouette and uses the ramp', () => {
const pal = pixel.resolvePalette(['#143024', '#2f6e2f', '#4b9a36', '#7cc243', '#875530']);
const canvas = new pixel.Canvas(32, 40, pal);
const p = new pixel.Painter(canvas);
p.apply({ op: 'rect', x: 14, y: 20, w: 4, h: 20, color: '#875530' });
p.apply({ op: 'circle', cx: 16, cy: 14, r: 10, color: '#143024' });
const trunkBefore = canvas.get(15, 35);
p.apply({ op: 'leaves', colors: ['#143024', '#2f6e2f', '#4b9a36', '#7cc243'], density: 1, seed: 3, spill: false });
assert.strictEqual(canvas.get(15, 35), trunkBefore, 'the trunk is not painted over');
assert.strictEqual(canvas.get(0, 39), 0, 'nothing outside the silhouette');
const used = opaqueColors(canvas);
for (const c of ['#2f6e2f', '#4b9a36', '#7cc243']) assert.ok(used.has(c), `${c} used`);
assert.throws(() => p.apply({ op: 'leaves', colors: ['#143024'] }), /rampa/);
});
test('pixel: translucent palette colours (shadows) render with real alpha', () => {
const canvas = new pixel.Canvas(4, 1, pixel.resolvePalette(['#000000', '#1a0a2450']));
assert.deepStrictEqual(canvas.palette, ['#000000', '#1a0a2450']);
const p = new pixel.Painter(canvas);
p.apply({ op: 'pixels', points: [[0, 0, '#1a0a2450'], [1, 0, '#000000']] });
const rgba = pixel.render(canvas, { scale: 1 });
assert.strictEqual(rgba[3], 0x50);
assert.strictEqual(rgba[7], 255);
// opaque requests never snap to the translucent colour
assert.strictEqual(canvas.nearest([30, 10, 36]), 1);
assert.match(pixel.toneStats(canvas), /#000000 %100/);
});
test('pixel: foliage builds a crown from leaf sprites with all five tones', () => {
const ramp = ['#06200f', '#0f3f17', '#22702a', '#3f9c38', '#86d64c'];
const canvas = new pixel.Canvas(48, 48, pixel.resolvePalette(ramp));
new pixel.Painter(canvas).apply({ op: 'foliage', colors: ramp, clusters: [[24, 24, 14], [14, 16, 8], [34, 16, 8]], seed: 2 });
const used = opaqueColors(canvas);
for (const c of ramp) assert.ok(used.has(c), `${c} used`);
assert.strictEqual(canvas.get(0, 47), 0);
assert.throws(() => new pixel.Painter(canvas).apply({ op: 'foliage', colors: ramp.slice(0, 3), clusters: [[1, 1, 1]] }), /5 tonluk/);
});
test('pixel: wind animation keeps the base still and writes a looping GIF', () => {
const ramp = ['#06200f', '#0f3f17', '#22702a', '#3f9c38', '#86d64c'];
const canvas = new pixel.Canvas(24, 40, pixel.resolvePalette([...ramp, '#55301c', '#1a0a2450']));
const p = new pixel.Painter(canvas);
p.apply({ op: 'rect', x: 10, y: 18, w: 4, h: 20, color: '#55301c' });
p.apply({ op: 'ellipse', x: 4, y: 36, w: 16, h: 4, color: '#1a0a2450', only: 'transparent' });
p.apply({ op: 'foliage', colors: ramp, clusters: [[12, 10, 9]], seed: 1 });
const frames = pixel.windFrames(canvas, { frames: 6, strength: 2, pivot: 20, colors: ramp, flutter: 0.1 });
assert.strictEqual(frames.length, 6);
for (const f of frames) for (let x = 0; x < 24; x++) assert.strictEqual(f.get(x, 30), canvas.get(x, 30), 'below the pivot nothing moves');
assert.ok(frames.some((f) => f.data.some((v, i) => v !== frames[0].data[i])), 'frames differ');
const gif = pixel.encodeGIF(frames, { scale: 2, background: '#8fbf6a' });
assert.strictEqual(gif.toString('ascii', 0, 6), 'GIF89a');
assert.strictEqual(gif.readUInt16LE(6), 48);
assert.strictEqual(gif[gif.length - 1], 0x3b);
assert.strictEqual(pixel.sheetOf(frames).w, 144);
});
test('pixel: ramps step evenly from cool shadows to warm lights', () => {
const ramp = pixel.makeRamp('#3e8948', { steps: 7 });
assert.strictEqual(ramp.length, 7);
assert.ok(ramp.includes('#3e8948'), 'the base colour is one of the tones');
const L = ramp.map((h) => pixel.oklch(pixel.parseHex(h)).L);
for (let i = 1; i < L.length; i++) assert.ok(L[i] > L[i - 1], 'dark → light');
const hue = (h) => pixel.oklch(pixel.parseHex(h)).h;
const base = hue('#3e8948');
assert.ok(hue(ramp[0]) > base + 10, 'shadow turns toward blue-violet');
assert.ok(hue(ramp[6]) < base - 10, 'light turns toward yellow');
for (const h of pixel.makeRamp('#808080', { steps: 5 })) assert.match(h, /^#[0-9a-f]{6}$/);
});
test('pixel: lint flags flat fills and few tones, passes shaded work', () => {
const flat = new pixel.Canvas(16, 16, pixel.resolvePalette(['#3a4466', '#262b44']));
flat.data.fill(1);
for (let x = 0; x < 16; x += 4) flat.set(x, 3, 2);
const report = pixel.lint(flat, { tile: true });
assert.match(report, /DÜZ DOLGU/);
assert.match(report, /AZ TONLU MALZEME/);
const ramp = pixel.makeRamp('#3e8948', { steps: 7 });
const ball = new pixel.Canvas(32, 32, ramp);
for (let y = 0; y < 32; y++) {
for (let x = 0; x < 32; x++) {
const dx = (x + 0.5 - 16) / 13;
const dy = (y + 0.5 - 16) / 13;
const d = dx * dx + dy * dy;
if (d > 1) continue;
// light from the top-left, tone bands broken up by a checker
const t = Math.max(0, Math.min(1, 0.5 - 0.45 * (dx + dy) - 0.25 * d + ((x + y) % 2 ? 0.06 : -0.06)));
ball.set(x, y, 2 + Math.round(t * (ramp.length - 2)));
}
}
new pixel.Painter(ball).apply({ op: 'selout' });
const ok = pixel.lint(ball);
assert.doesNotMatch(ok, /✗/, ok);
assert.match(ok, /ışık sol-üstten/);
});
test('pixel: selout, ao and rim recolour from the palette', () => {
const pal = pixel.resolvePalette(['#000000', '#402020', '#804040', '#c08080', '#ffe0e0', '#808080', '#404040']);
const c = new pixel.Canvas(10, 10, pal);
const p = new pixel.Painter(c);
p.apply({ op: 'rect', x: 2, y: 2, w: 6, h: 6, color: '#804040', fill: true });
p.apply({ op: 'selout' });
assert.strictEqual(c.palette[c.get(2, 5) - 1], '#402020', 'lit edge: one step darker');
assert.strictEqual(c.palette[c.get(7, 5) - 1], '#000000', 'shadow edge: two steps darker');
p.apply({ op: 'rim', side: 'top-left' });
assert.strictEqual(c.palette[c.get(3, 3) - 1], '#c08080', 'rim just inside the outline');
const floor = new pixel.Canvas(4, 6, pal);
const fp = new pixel.Painter(floor);
fp.apply({ op: 'rect', x: 0, y: 0, w: 4, h: 2, color: '#404040', fill: true });
fp.apply({ op: 'rect', x: 0, y: 2, w: 4, h: 4, color: '#c08080', fill: true });
fp.apply({ op: 'ao', from: ['#404040'], depth: 2 });
const lumAt = (x, y) => {
const rgb = floor.rgb[floor.get(x, y) - 1];
return 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2];
};
assert.ok(lumAt(1, 2) < lumAt(1, 5), 'darkest at the contact');
assert.strictEqual(floor.palette[floor.get(1, 5) - 1], '#c08080', 'beyond depth unchanged');
});
test('pixel: remap spreads materials over their ramps with a coloured outline', () => {
const w = 96;
const data = new Uint8Array(w * w * 4);
for (let y = 0; y < w; y++) {
for (let x = 0; x < w; x++) {
const i = (y * w + x) * 4;
const dx = (x - 48) / 36;
const dy = (y - 48) / 36;
if (dx * dx + dy * dy > 1) {
data.set([255, 0, 255, 255], i);
continue;
}
const shade = Math.max(0, Math.min(1, 0.55 - 0.5 * (dx + dy)));
data.set(x < 48 ? [Math.round(60 + 180 * shade), Math.round(30 + 60 * shade), 40, 255] : [40, Math.round(60 + 160 * shade), 70, 255], i);
}
}
const ramps = { kirmizi: pixel.makeRamp('#c03030', { steps: 6 }), yesil: pixel.makeRamp('#3e8948', { steps: 6 }) };
const { canvas, report } = pixel.remap({ w, h: w, data }, { width: 24, ramps, background: '#ff00ff' });
assert.strictEqual(canvas.w, 24);
assert.match(report, /kirmizi: \d+ piksel, [4-6]\/6 ton/);
assert.match(report, /yesil: \d+ piksel, [4-6]\/6 ton/);
const left = canvas.palette[canvas.get(0, 12) - 1] || canvas.palette[canvas.get(1, 12) - 1];
assert.ok([ramps.kirmizi[0]].includes(left), `outline is the material's darkest tone (${left})`);
assert.throws(() => pixel.remap({ w, h: w, data }, { ramps: { a: ['#000000', '#ffffff'] } }), /en az 3 ton/);
});
test('pixel: character check and tile variants', () => {
const pal = pixel.resolvePalette(['#e43b44', '#ffd3a3', '#181425']);
const frame = (eye) => {
const c = new pixel.Canvas(8, 12, pal);
const p = new pixel.Painter(c);
p.apply({ op: 'rect', x: 2, y: 1, w: 4, h: 10, color: '#ffd3a3', fill: true });
p.apply({ op: 'rect', x: 3, y: 3, w: eye, h: 1, color: '#e43b44', fill: true });
return c;
};
const sheet = new pixel.Canvas(24, 12, pal);
[frame(1), frame(1), frame(3)].forEach((f, i) => {
for (let y = 0; y < 12; y++) for (let x = 0; x < 8; x++) sheet.set(i * 8 + x, y, f.get(x, y));
});
const frames = pixel.splitSheet(sheet, 8, 12);
assert.strictEqual(frames.length, 3);
const out = pixel.characterCheck({ parts: { goz: ['#e43b44'] }, palette: ['#e43b44', '#ffd3a3'] }, frames);
assert.match(out, /✗ kare 2.*goz 3 px.*büyük/);
assert.doesNotMatch(out, /✗ kare 0/);
const tile = new pixel.Canvas(16, 16, pixel.makeRamp('#733e39', { steps: 5 }));
new pixel.Painter(tile).apply({ op: 'noise', colors: tile.palette, density: 1, seed: 3 });
const { sheet: vars, map, count } = pixel.tileVariants(tile, { variants: 3, border: 2 });
assert.strictEqual(count, 4);
assert.strictEqual(vars.w, 64);
assert.strictEqual(map.w, 48);
for (let i = 1; i < 4; i++) for (let y = 0; y < 16; y++) {
assert.strictEqual(vars.get(i * 16, y), tile.get(0, y), 'border kept so variants still join');
assert.strictEqual(vars.get(i * 16 + 15, y), tile.get(15, y));
}
});
test('pixel: finished PNGs are read back exactly; photos are refused', () => {
const c = new pixel.Canvas(4, 4, pixel.resolvePalette(['#112233', '#1a102480']));
c.set(1, 1, 1);
c.set(2, 2, 2);
const png = pixel.encodePNG(4, 4, pixel.render(c, { scale: 1 }));
const back = pixel.canvasFromImage(pixel.decodeImage(png));
assert.strictEqual(back.palette[back.get(1, 1) - 1], '#112233');
assert.strictEqual(back.palette[back.get(2, 2) - 1], '#1a102480');
assert.strictEqual(back.get(0, 0), 0);
const w = 32;
const data = new Uint8Array(w * w * 4);
for (let i = 0; i < w * w; i++) data.set([i % 256, (i * 7) % 256, (i * 13) % 256, 255], i * 4);
assert.throws(() => pixel.canvasFromImage({ w, h: w, data }), /pixel art değil/);
});
// Template whose tile k (1 fill, 2 single, 3 vertical, 4 horizontal, 5 inner) is painted in colour k.
function codedTemplate(tw = 4) {
const t = new pixel.Canvas(tw * 5, tw, ['#100000', '#200000', '#300000', '#400000', '#500000']);
for (let y = 0; y < tw; y++) for (let x = 0; x < tw * 5; x++) t.set(x, y, Math.floor(x / tw) + 1);
return t;
}
function quarterColours(canvas, x0, y0, tw) {
const h = tw / 2;
// Template code from the colour (#k00000), so palette order does not matter.
return [[0, 0], [h, 0], [0, h], [h, h]].map(([dx, dy]) => {
const v = canvas.get(x0 + dx, y0 + dy);
return v ? Number(canvas.palette[v - 1][1]) : 0;
});
}
test('pixel: 5-tile template → 47-tile blob sheet in the Godot layout', () => {
const tpl = codedTemplate(4);
assert.deepStrictEqual(pixel.sheetKind(tpl), { kind: 'template', tw: 4 });
const sheet = pixel.buildBlobTileset(tpl);
assert.strictEqual(sheet.w, 48);
assert.strictEqual(sheet.h, 16);
assert.deepStrictEqual(pixel.sheetKind(sheet), { kind: 'blob', tw: 4 });
assert.deepStrictEqual(quarterColours(sheet, 0, 0, 4), [2, 2, 3, 3]); // top end of a column
assert.deepStrictEqual(quarterColours(sheet, 9 * 4, 2 * 4, 4), [1, 1, 1, 1]); // full inside
assert.deepStrictEqual(quarterColours(sheet, 10 * 4, 4, 4), [0, 0, 0, 0]); // the unused cell
assert.throws(() => pixel.buildBlobTileset(new pixel.Canvas(15, 3, ['#000000'])), /çift/);
});
test('pixel: pixel_map autotile picks quarters from all 8 neighbours', () => {
const dir = tmpDir();
pixel.save(dir, 'tpl', codedTemplate(4));
const map = pixel.buildMap(dir, { rows: ['www.', 'www.', 'w.w.', '...w'], autotile: { w: 'tpl' } });
assert.deepStrictEqual(quarterColours(map, 4, 4, 4), [1, 1, 4, 4]); // middle of the block's bottom row: bottom edge
assert.deepStrictEqual(quarterColours(map, 4, 0, 4), [1, 1, 1, 1]); // inside (the map border counts as the same terrain)
assert.deepStrictEqual(quarterColours(map, 8, 8, 4), [3, 3, 2, 2]); // bottom end of a column
assert.deepStrictEqual(quarterColours(map, 8, 4, 4), [1, 3, 5, 3]); // right column of the block: right edge, inner corner where the lower-left diagonal is empty
assert.deepStrictEqual(quarterColours(map, 0, 8, 4), [1, 3, 4, 2]); // left column end: border, right edge, bottom edge, corner
assert.deepStrictEqual(quarterColours(map, 12, 12, 4), [2, 4, 3, 1]); // map corner: right and bottom count as terrain
pixel.save(dir, 'blob', pixel.buildBlobTileset(codedTemplate(4)));
const viaSheet = pixel.buildMap(dir, { rows: ['www.', 'www.', 'w.w.', '...w'], autotile: { w: 'blob' } });
for (let y = 0; y < map.h; y++) for (let x = 0; x < map.w; x++) assert.strictEqual(quarterColours(viaSheet, x, y, 0)[0], quarterColours(map, x, y, 0)[0]);
});
test('pixel: WFC keeps the sample palette and every 2x2 window of the sample', () => {
const sample = new pixel.Canvas(4, 4, ['#000000', '#ffffff']);
for (let y = 0; y < 4; y++) for (let x = 0; x < 4; x++) sample.set(x, y, ((x >> 1) + y) % 2 ? 2 : 1);
const windows = new Set();
for (let y = 0; y < 4; y++) for (let x = 0; x < 4; x++) windows.add([sample.get(x, y), sample.get((x + 1) % 4, y), sample.get(x, (y + 1) % 4), sample.get((x + 1) % 4, (y + 1) % 4)].join());
const { canvas } = pixel.wfcOverlap(sample, { width: 12, height: 10, N: 2, symmetry: 1, seed: 3 });
assert.strictEqual(canvas.w, 12);
for (let y = 0; y < 10; y++) {
for (let x = 0; x < 12; x++) {
const win = [canvas.get(x, y), canvas.get((x + 1) % 12, y), canvas.get(x, (y + 1) % 10), canvas.get((x + 1) % 12, (y + 1) % 10)].join();
assert.ok(windows.has(win), `window ${win} at ${x},${y}`);
}
}
const again = pixel.wfcOverlap(sample, { width: 12, height: 10, N: 2, symmetry: 1, seed: 3 }).canvas;
assert.deepStrictEqual([...again.data], [...canvas.data]);
});
test('pixel: Lospec palettes and quantising a fixed image', () => {
const pal = pixel.resolvePalette('lospec:endesga-32');
assert.strictEqual(pal.length, 32);
assert.ok(pixel.findPalettes('endesga').some((p) => p.key === 'endesga-16'));
assert.throws(() => pixel.resolvePalette('lospec:yok-boyle-palet'), /bulunamadı/);
const w = 8;
const data = Buffer.alloc(w * w * 4);
for (let i = 0; i < w * w; i++) data.set([i * 3, 255 - i * 3, 40, i === 0 ? 0 : 255], i * 4);
const canvas = pixel.quantizeImage({ w, h: w, data }, 4);
assert.ok(canvas.palette.length <= 4);
assert.strictEqual(canvas.data[0], 0);
assert.ok(canvas.data.slice(1).every((v) => v > 0));
const snapped = pixel.quantizeImage({ w, h: w, data }, 0, { palette: ['#000000', '#ffffff'] });
assert.deepStrictEqual(snapped.palette, ['#000000', '#ffffff']);
});
|