本文整理汇总了TypeScript中GameOfLifeTransformer.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getWorld
QUnit.test(name("Birth wins when dead"), assert => {
const t = GameOfLifeTransformer.create([3], [3]);
const nextWorld = new Array2D(3, 3, false);
const w = getWorld(3, 1, 1);
t.transform(w, nextWorld);
assert.strictEqual(nextWorld.get(1, 1), true);
});
示例2:
QUnit.test(name("Overlapping birth"), assert => {
const t = GameOfLifeTransformer.create([], [0]);
const w = new Array2D(3, 4, false);
const nextWorld = new Array2D(3, 4, false);
t.transform(w, nextWorld);
assert.strictEqual(nextWorld.get(1, 2), true);
assert.strictEqual(nextWorld.get(1, 3), true);
});
示例3: Array2D
QUnit.test(name("Single survival number when dead"), assert => {
const nextWorld = new Array2D(3, 3, false);
for (let n = 0; n < 9; n++) {
const t = GameOfLifeTransformer.create([n], []);
for (let neighbors = 0; neighbors < 9; neighbors++) {
const w = getWorld(neighbors, 1, 1);
t.transform(w, nextWorld);
assert.strictEqual(nextWorld.get(1, 1), false);
}
}
});
示例4: Array2D
canvasElement.width = width * pointSize;
canvasElement.height = height * pointSize;
const ctx = canvasElement.getContext("2d")!;
ctx.fillStyle = `rgb(${String(0)}, ${String(0)}, ${String(0)})`;
document.getElementById("content")!.appendChild(canvasElement);
const renderer = RectRenderer.create(ctx, pointSize);
let currentWorld = new Array2D(height, width, false);
let nextWorld = new Array2D(height, width, false);
for (let row = 0; row < height; row++) {
for (let column = 0; column < width; column++) {
currentWorld.set(row, column, Math.random() < 0.5001);
}
}
const transformer = GameOfLifeTransformer.create(survival, birth);
setInterval(() => {
renderer.render(currentWorld);
transformer.transform(currentWorld, nextWorld);
const h = currentWorld;
currentWorld = nextWorld;
nextWorld = h;
}, 50);