GithubHelp home page GithubHelp logo

hhy5277 / wasm-fun Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lingdong-/wasm-fun

0.0 2.0 0.0 365 KB

Non-trivial programs in hand-written WebAssembly

License: The Unlicense

Python 0.07% HTML 8.35% WebAssembly 91.57%

wasm-fun's Introduction

wasm-fun

Non-trivial programs in hand-written WebAssembly

This repo is a collection of useful algorithms written from scratch in WebAssembly text format (.wat) and assembled to .wasm via wabt.

See Overview section for a list of programs included. See wat folder for the fully-commented and well-explained source code. See wasm for compiled binaries you can grab and use (with your JS projects). See tests for usage examples.

Despite that the algorithms are non-trivial, the assembled binaries are extremely small (compared to say what you get from emscripten)! Average file size is ~900 bytes.

Motivation

I find WebAssembly a wonderful technology, and have been compiling C's and C++'s to wasm via emscripten for many projects. So I thought I should learn at least learn the "real" thing -- coding in WebAssembly directly. Fortunately, the lisp-like S-expressions makes the language quite pleasant to work with.

I haven't found many handwritten examples beyond the "fizzbuzz" and the "99 beers". (This Conway's Game of Life in WebAssembly gave me a lot of inspiration though). So I started my own little collection of algorithms I enjoyed, in hand-written WebAssembly, with ample comments and explanations for the reader.

I think WebAssembly is the sort of language where the beauty is derived from its simplicity.

Overview

thinning.wat
Skeletonization/thinning of binary images. Implements Zhang-Suen (1984). Paper
disttransform.wat
Compute distance transform of binary images. Implements Meijster distance. Paper
findcontours.wat
Trace contours from binary images (vector output). This is the same as OpenCV's findContours. Implements Suzuki-Abe (1983). Paper
browniantree.wat
Generate brownian fractal trees (aka Diffusion-limited aggregation).
mazegen.wat
Generate mazes using Wilson's algorithm, which guarantees an unbiased sample from the uniform distribution over all mazes.
malloc.wat
Very baseline 32-bit implicit-free-list first-fit malloc.
traceskeleton.wat
Retrieve topological skeleton as a set of polylines from binary images. Original algorithm. Includes a malloc implementation and a linked list implementation. ~300% faster than the version complied with emscripten (and ~10x smaller), ~500% faster than vanilla Javascript.
containers.wat
Implements STL-like polymorphic container types arr<T> (continous resizable array), list<T> (doubly linked list) and map<T,T> (hash table).
random.wat
Uniform, Perlin, Gaussian, and exponential randomness.

wasm-fun's People

Contributors

lingdong- avatar

Watchers

 avatar  avatar

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.