Giter VIP home page Giter VIP logo

go-wasm-ball-simulator's Introduction

Go Wasm Ball Simulator

A simple simulator of a ball bouncing around your screen that is affected by gravity, restitution, and friction. It can be dragged and flung around via mouse.

Live Demo

A live demo can be viewed here: https://insulince.github.io/go-wasm-ball-simulator/

Do note that because GitHub Pages is pretty strict about what you can use on its hosting platform, the wasm_exec.js may become out of date (it isn't updated dynamically), so the live demo may stop working at some point.

Structure

bin/
    [server binary]
serve/
    bin/
        [wasm binary]
        [wasm_exec.js]
    default.html
    index.html
    stles.css
    wasm-init.js
server/
    main.go
wasm/
    models/
        ball.go
    window/
        window.go
    main.go

bin/ stores the server binary.

serve/ is the root directory that files will be served from.

serve/bin/ stores the Wasm binary and the wasm_exec.js file.

serve/index.html is the landing page. Displays a loader until Wasm is ready.

serve/default.html is the html that will be swapped out as soon as web assembly initializes.

serve/wasm-init.js is the JavaScript glue needed to connect to Go's Wasm.

server/ contains the source code for the file server.

wasm/ contains the source code for the web assembly portion of this project.

wasm/window/ contains a set of helper functions for interacting with the DOM.

Compilation and Running

Compile the server:

go build -o "./bin/server" "./server"

Compile the Wasm:

GOARCH=wasm GOOS=js go build -o "./serve/bin/out.wasm" "./wasm"

Run the server to download wasm_exec.js into ./serve/bin and to begin serving files (Set your own value for port):

PORT={port} "./bin/server"

The server will begin downloading the latest wasm_exec.js and once complete it will be ready to serve the project files.

You can now access the project at http://localhost:{port}.

NOTE

Go's Wasm port is experimental and is constantly changing. One thing I have noticed is that the version of the wasm_exec.js file being downloaded today (10/25/18) seems to be broken. Upon checking my local storage I found an older working copy, but I can see some changs have been made to that file since then, so it is actively being worked on. If this doesn't work today, wait a while and they will update the exec file.

go-wasm-ball-simulator's People

Contributors

insulince 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.