🚀 generate frames
This commit is contained in:
@@ -10,7 +10,7 @@ import { Point } from "@snk/compute/point";
|
||||
const copySnake = (x: Point[]) => x.map((p) => ({ ...p }));
|
||||
|
||||
export const run = async () => {
|
||||
const options = {
|
||||
const drawOptions = {
|
||||
sizeBorderRadius: 2,
|
||||
sizeCell: 16,
|
||||
sizeDot: 12,
|
||||
@@ -22,35 +22,34 @@ export const run = async () => {
|
||||
|
||||
const gameOptions = { maxSnakeLength: 5 };
|
||||
|
||||
const grid = generateGrid(14, 7, { colors: [1, 2, 3, 4], emptyP: 3 });
|
||||
const grid0 = generateGrid(14, 7, { colors: [1, 2, 3, 4], emptyP: 3 });
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = options.sizeCell * (grid.width + 4);
|
||||
canvas.height = options.sizeCell * (grid.height + 4) + 100;
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
|
||||
document.body.appendChild(canvas);
|
||||
|
||||
const snake = [
|
||||
const snake0 = [
|
||||
{ x: 4, y: -1 },
|
||||
{ x: 3, y: -1 },
|
||||
{ x: 2, y: -1 },
|
||||
{ x: 1, y: -1 },
|
||||
{ x: 0, y: -1 },
|
||||
];
|
||||
const stack: Color[] = [];
|
||||
const stack0: Color[] = [];
|
||||
|
||||
const chain = computeBestRun(grid, snake, gameOptions);
|
||||
const chain = computeBestRun(grid0, snake0, gameOptions);
|
||||
|
||||
const update = (x: number) => {
|
||||
const s = copySnake(snake);
|
||||
const q = stack.slice();
|
||||
const g = copyGrid(grid);
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = drawOptions.sizeCell * (grid0.width + 4);
|
||||
canvas.height = drawOptions.sizeCell * (grid0.height + 4) + 100;
|
||||
document.body.appendChild(canvas);
|
||||
const ctx = canvas.getContext("2d")!;
|
||||
|
||||
for (let i = 0; i < x; i++) step(g, s, q, chain[i], gameOptions);
|
||||
const update = (n: number) => {
|
||||
const snake = copySnake(snake0);
|
||||
const stack = stack0.slice();
|
||||
const grid = copyGrid(grid0);
|
||||
|
||||
for (let i = 0; i < n; i++) step(grid, snake, stack, chain[i], gameOptions);
|
||||
|
||||
ctx.clearRect(0, 0, 9999, 9999);
|
||||
drawWorld(ctx, g, s, q, options);
|
||||
drawWorld(ctx, grid, snake, stack, drawOptions);
|
||||
};
|
||||
|
||||
const input: any = document.createElement("input");
|
||||
|
||||
Reference in New Issue
Block a user