Skip to content

Commit eed6b7a

Browse files
committed
Add WASM demo to github page
1 parent 503c7a1 commit eed6b7a

File tree

12 files changed

+1035
-0
lines changed

12 files changed

+1035
-0
lines changed

wasm-demo/pkg/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# The Minimal Demo for Plotters + WASM
2+
3+
To build the demo you need [wasm-pack](https://rustwasm.github.io/docs/book/game-of-life/setup.html).
4+
5+
Then you can run it locally either using `npm` and `webpack-dev-server` or
6+
just with static web server.
7+
8+
The following script will install needed software and run the server via `npm`.
9+
```
10+
./start-server.sh
11+
```
12+
13+
For Windows users without Bash, `start-server.bat` can be used to
14+
launch the server.
15+
16+
```
17+
start-server.bat
18+
```
19+
20+
## Developing with NPM
21+
Please use [rust-wasm guide](https://rustwasm.github.io/docs/book/game-of-life/setup.html) for initial setup .
22+
Then you can run the demo locally using `npm`:
23+
```bash
24+
wasm-pack build
25+
cd www
26+
npm install
27+
npm start
28+
```
29+
30+
This will start a dev server which will automatically reload your page
31+
whenever you change anything in `www` directory. To update `rust` code
32+
call `wasm-pack build` manually.
33+
34+
## Developing without dependenices
35+
If you don't want to use `npm` here's how you can run the example
36+
using any web server. We are using rust [basic-http-server](https://github.com/brson/basic-http-server), but
37+
any web server will do.
38+
39+
```bash
40+
# Install web server (instead you can use your local nginx for example)
41+
cargo install basic-http-server
42+
wasm-pack build --target web # Note `--target web`
43+
basic-http-server
44+
```
45+
46+
Then open http://127.0.0.1:4000/www

wasm-demo/pkg/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "wasm-demo",
3+
"collaborators": [
4+
"Hao Hou <[email protected]>"
5+
],
6+
"version": "0.1.0",
7+
"files": [
8+
"wasm_demo_bg.wasm",
9+
"wasm_demo.js",
10+
"wasm_demo.d.ts"
11+
],
12+
"module": "wasm_demo.js",
13+
"types": "wasm_demo.d.ts",
14+
"sideEffects": false
15+
}

wasm-demo/pkg/wasm_demo.d.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Type used on the JS side to convert screen coordinates to chart
5+
* coordinates.
6+
*/
7+
export class Chart {
8+
free(): void;
9+
/**
10+
* Draw provided power function on the canvas element using it's id.
11+
* Return `Chart` struct suitable for coordinate conversion.
12+
* @param {string} canvas_id
13+
* @param {number} power
14+
* @returns {Chart}
15+
*/
16+
static power(canvas_id: string, power: number): Chart;
17+
/**
18+
* Draw Mandelbrot set on the provided canvas element.
19+
* Return `Chart` struct suitable for coordinate conversion.
20+
* @param {HTMLCanvasElement} canvas
21+
* @returns {Chart}
22+
*/
23+
static mandelbrot(canvas: HTMLCanvasElement): Chart;
24+
/**
25+
* @param {HTMLCanvasElement} canvas
26+
* @param {number} pitch
27+
* @param {number} yaw
28+
*/
29+
static plot3d(canvas: HTMLCanvasElement, pitch: number, yaw: number): void;
30+
/**
31+
* This function can be used to convert screen coordinates to
32+
* chart coordinates.
33+
* @param {number} x
34+
* @param {number} y
35+
* @returns {Point | undefined}
36+
*/
37+
coord(x: number, y: number): Point | undefined;
38+
}
39+
/**
40+
* Result of screen to chart coordinates conversion.
41+
*/
42+
export class Point {
43+
free(): void;
44+
/**
45+
*/
46+
x: number;
47+
/**
48+
*/
49+
y: number;
50+
}
51+
52+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
53+
54+
export interface InitOutput {
55+
readonly memory: WebAssembly.Memory;
56+
readonly __wbg_chart_free: (a: number) => void;
57+
readonly __wbg_point_free: (a: number) => void;
58+
readonly __wbg_get_point_x: (a: number) => number;
59+
readonly __wbg_set_point_x: (a: number, b: number) => void;
60+
readonly __wbg_get_point_y: (a: number) => number;
61+
readonly __wbg_set_point_y: (a: number, b: number) => void;
62+
readonly chart_power: (a: number, b: number, c: number, d: number) => void;
63+
readonly chart_mandelbrot: (a: number, b: number) => void;
64+
readonly chart_plot3d: (a: number, b: number, c: number, d: number) => void;
65+
readonly chart_coord: (a: number, b: number, c: number) => number;
66+
readonly __wbindgen_malloc: (a: number) => number;
67+
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
68+
readonly __wbindgen_exn_store: (a: number) => void;
69+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
70+
}
71+
72+
/**
73+
* Synchronously compiles the given `bytes` and instantiates the WebAssembly module.
74+
*
75+
* @param {BufferSource} bytes
76+
*
77+
* @returns {InitOutput}
78+
*/
79+
export function initSync(bytes: BufferSource): InitOutput;
80+
81+
/**
82+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
83+
* for everything else, calls `WebAssembly.instantiate` directly.
84+
*
85+
* @param {InitInput | Promise<InitInput>} module_or_path
86+
*
87+
* @returns {Promise<InitOutput>}
88+
*/
89+
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;

0 commit comments

Comments
 (0)