-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
50 lines (41 loc) · 1.23 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Go wasm</title>
</head>
<body>
<script src="wasm_exec.js"></script>
<script>
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}
const go = new Go();
let mod, inst;
WebAssembly.instantiateStreaming(fetch("lib.wasm"), go.importObject).then( async result => {
mod = result.module;
inst = result.instance;
await go.run(inst);
}
);
function preparePixelData() {
let expression = document.getElementById("expression").value
let p = []
for(y = 0; y < 256; y++) {
p[y] = []
for(x = 0; x < 256; x++) {
p[y][x] = eval(expression + "% 256")
}
}
showPic(JSON.stringify(p))
}
</script>
<p>Enter mathematical expression for x and/or y: (in JS)</p>
<input id="expression"/>
<button onClick="preparePixelData()" id="addButton">showPic</button>
<img src="" id="img"/>
</body>
</html>