diff --git a/src/utils/draw.js b/src/utils/draw.js index 6b6113a..636bf33 100644 --- a/src/utils/draw.js +++ b/src/utils/draw.js @@ -27,7 +27,7 @@ export function drawMandelbrot(image) { } const set = get(settings) - mandelbrot.calc(set.lx, set.rx, w, h) + mandelbrot.calc(set.lx, set.rx, set.yc, w, h) const pixelsPtr = mandelbrot.pixels() const pixels = new Float32Array(memory.buffer, pixelsPtr, len) diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 4edd566..3a291f8 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -45,22 +45,21 @@ impl Mandelbrot { /// /// * `lx` - Left coordinate of x axis (complex plane) /// * `rx` - Right coordinate of x axis (complex plane) + /// * `yc` - Center of y axis (complex plane) /// * `w` - Width of display (canvas plane) - how many points to calculate /// * `h` - Height of display (canvas plane) - pub fn calc(&mut self, lx: f64, rx: f64, w: u16, h: u16) { + pub fn calc(&mut self, lx: f64, rx: f64, yc: f64, w: u16, h: u16) { // total width of x axis (complex plane) let xwidth = rx - lx; // scale coefficient between complex plane and canvas let scale = (w as f64) / xwidth; - // height of y axis + // complex height of y axis let yheight = (h as f64) / scale; - // top and down y coordinate - // now hardcode, y axis on canvas center - let ty = yheight / (2 as f64); - // let dy = ty; + // top complex y coordinate + let ty = yc + (yheight / 2.0); // x display, y display let (mut xd, mut yd); @@ -75,10 +74,6 @@ impl Mandelbrot { pub fn pixels(&self) -> *const f32 { self.pixels.as_ptr() } - - pub fn scale2x() { - unimplemented!(); - } } fn check_series(x: f64, i: f64) -> f32 {