mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-26 21:21:54 +00:00
Improve mandelbort example (#308)
This commit is contained in:
@ -30,14 +30,19 @@ var ctx = cnv.getContext("2d");
|
||||
var bcr = cnv.getBoundingClientRect();
|
||||
|
||||
// Compute the size of the viewport
|
||||
var width = bcr.width | 0;
|
||||
var width = bcr.width | 0;
|
||||
var height = bcr.height | 0;
|
||||
var ratio = window.devicePixelRatio || 1;
|
||||
width *= ratio;
|
||||
height *= ratio;
|
||||
var size = width * height;
|
||||
var byteSize = size << 1; // discrete color indices in range [0, 2047] (here: 2b per pixel)
|
||||
|
||||
cnv.width = width;
|
||||
cnv.width = width;
|
||||
cnv.height = height;
|
||||
|
||||
ctx.scale(ratio, ratio);
|
||||
|
||||
// Compute the size of and instantiate the module's memory
|
||||
var memory = new WebAssembly.Memory({ initial: ((byteSize + 0xffff) & ~0xffff) >>> 16 });
|
||||
var mem = new Uint16Array(memory.buffer);
|
||||
@ -48,7 +53,7 @@ var argb = new Uint32Array(imageData.data.buffer);
|
||||
fetch("build/optimized.wasm")
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.instantiate(buffer, {
|
||||
env: { memory: memory },
|
||||
env: { memory },
|
||||
Math
|
||||
}))
|
||||
.then(module => {
|
||||
@ -56,7 +61,9 @@ fetch("build/optimized.wasm")
|
||||
var computeLine = exports.computeLine;
|
||||
var updateLine = function(y) {
|
||||
var yx = y * width;
|
||||
for (let x = 0; x < width; ++x) argb[yx + x] = colors[mem[yx + x]];
|
||||
for (let x = 0; x < width; ++x) {
|
||||
argb[yx + x] = colors[mem[yx + x]];
|
||||
}
|
||||
};
|
||||
|
||||
// Compute an initial balanced version of the set.
|
||||
|
Reference in New Issue
Block a user