當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript GameOfLifeTransformer.create函數代碼示例

本文整理匯總了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);
});
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:9,代碼來源:GameOfLifeTransformer_test.ts

示例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);
});
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:10,代碼來源:GameOfLifeTransformer_test.ts

示例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);
        }
    }
});
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:15,代碼來源:GameOfLifeTransformer_test.ts

示例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);
開發者ID:cfuehrmann,項目名稱:GameOfLife,代碼行數:31,代碼來源:World.ts


注:本文中的GameOfLifeTransformer.create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。