Git Product home page Git Product logo

wasm-game-of-life's Introduction

Introduction

这是一个 Conway‘s game of life 的 wasm 模块,使用 webpack4 在 ES Module 项目中使用,可以通过该模块实现游戏游戏对 wasm 性能有初步的了解,webassembly 兼容性

Install

npm install @bezos/wasm-game-of-life --save

Structure

struct Universe {
  width: usize,
  height: usize,
  cells: &[u8],
};

API

new()

默认构造一个 64*64 bit 的数组

import { Universe } from '@bezos/wasm-game-of-life'
const universe = Universe.new()

init()

初始化cells

universe.init()

reset()

清空cells

universe.reset()

cells()

获取cells内存地址

import { memory } from '@bezos/wasm-game-of-life/wasm_game_of_life_bg'
const { width, height } = universe
const cellsPtr = universe.cells()
const cells = new Uint8Array(memory.buffer, cellsPtr, (width * height) / 8)

tick()

根据上一个状态更新cells

requestAnimationFrame(function renderLoop() {
    universe.tick()
    drawSomething()
    requestAnimationFrame(renderLoop)
})

toggle_cell(row, col)

根据为止反转状态

universe.toggle_cell(row, col)

wasm-game-of-life's People

Contributors

lidongjies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

yyx-520 billgpt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.