Skip to content

Commit

Permalink
feat: pass center of y axis
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Apr 21, 2022
1 parent 4d9dd36 commit 91f0ba4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/utils/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit 91f0ba4

Please sign in to comment.