Compare commits

..

No commits in common. "8a7d8ec24c3fd602790c519e7ba52a644b3bf3a2" and "96daec016fe41de7b266103c99b65f01d1b735eb" have entirely different histories.

2 changed files with 3 additions and 20 deletions

View File

@ -40,7 +40,7 @@ export function picToBoard(pixels, board) {
const flat = pixels.reduce((acc, pixel, index) => { const flat = pixels.reduce((acc, pixel, index) => {
const i = index * 4; const i = index * 4;
const count = pixels[i] + pixels[i + 1] + pixels[i + 2]; const count = pixels[i] + pixels[i + 1] + pixels[i + 2];
const value = (count >= 255) & 1; const value = count >= 255 ? 1 : 0;
acc[index] = value; acc[index] = value;
return acc; return acc;
}, []); }, []);
@ -58,7 +58,8 @@ export function boardToPic(board) {
const img = new ImageData(board.width, board.height); const img = new ImageData(board.width, board.height);
const colors = [hexToRGB(live), hexToRGB(dead)]; const colors = [hexToRGB(live), hexToRGB(dead)];
board.grid.flat().reduce((acc, cell, index) => { board.grid.flat().reduce((acc, cell, index) => {
const color = colors[(cell === 1) & 1]; // TODO : bitshift operation instead of ternary
const color = cell === 1 ? colors[0] : colors[1];
const i = index * 4; const i = index * 4;
acc[i] = color[0]; acc[i] = color[0];
acc[i + 1] = color[1]; acc[i + 1] = color[1];

View File

@ -1,18 +0,0 @@
import { describe, expect, test } from "vitest";
import { evolve1d, create1dStateOneCell } from "src/modules/core.js";
import { presetRuleset } from "src/modules/preset.js";
describe("Core", () => {
test("evolve1d, rules73, 9 cells", () => {
const state = [0, 0, 0, 0, 1, 0, 0, 0, 0];
const got = evolve1d(state, presetRuleset[0].rules);
const valid = [1, 1, 1, 0, 0, 0, 1, 1, 1];
expect(got.length).toBe(state.length);
expect(got).toEqual(valid);
}),
test("create1dStateOneCell, 49 cells", () => {
const got = create1dStateOneCell(49);
expect(got.length).toBe(49);
expect(got[24]).toBe(1);
});
});