🚀 bootstrap workspace

This commit is contained in:
platane
2020-07-16 01:19:21 +02:00
commit e9654e7e66
14 changed files with 7679 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
import { Grid, Color } from "./grid";
const rand = (a: number, b: number) => Math.floor(Math.random() * (b - a)) + a;
export const generateGrid = (
width: number,
height: number,
options: { colors: Color[]; emptyP: number } = {
colors: [1, 2, 3],
emptyP: 2,
}
): Grid => {
const g = {
width,
height,
data: Array.from({ length: width * height }, () => {
const x = rand(-options.emptyP, options.colors.length);
return x < 0 ? null : options.colors[x];
}),
};
return g;
};