本文整理匯總了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);