mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-12 06:21:29 +00:00
Also link to the source from the demos
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
export function update(width: u32, height: u32, max: u32): void {
|
||||
// see: https://en.wikipedia.org/wiki/Mandelbrot_set
|
||||
|
||||
/** Computes the number of iterations in the rectangle `width` x `height`, limited to `max`. */
|
||||
export function compute(width: u32, height: u32, max: u32): void {
|
||||
var translateX = width / 1.6;
|
||||
var translateY = height / 2.0;
|
||||
var scale = 4.0 / width;
|
||||
@ -7,12 +10,14 @@ export function update(width: u32, height: u32, max: u32): void {
|
||||
for (let x: u32 = 0; x < width; ++x) {
|
||||
let real = (x - translateX) * scale;
|
||||
let iteration = <u32>0;
|
||||
for (let ix = 0.0, iy = 0.0; ix * ix + iy * iy <= 4.0; ++iteration) {
|
||||
let t = ix * ix - iy * iy + real;
|
||||
let ixsq: f64, iysq: f64;
|
||||
for (let ix = 0.0, iy = 0.0; (ixsq = ix * ix) + (iysq = iy * iy) <= 4.0; ++iteration) {
|
||||
let t = ixsq - iysq + real;
|
||||
iy = 2.0 * ix * iy + imaginary;
|
||||
ix = t;
|
||||
if (++iteration >= max) break;
|
||||
}
|
||||
// write normalized iterations to [0, width * height], row by row
|
||||
store<u8>(y * width + x, iteration * 255 / max);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user