diff --git a/mandelbrot.sublime-project b/mandelbrot.sublime-project index f47dd4e..62ed283 100644 --- a/mandelbrot.sublime-project +++ b/mandelbrot.sublime-project @@ -2,7 +2,14 @@ "folders": [ { - "path": "." + "path": ".", + "folder_exclude_patterns": [/*"//src",*/ "//wasm"] + }, + // { + // "path": "src" + // }, + { + "path": "wasm" } ], "build_systems": [ diff --git a/vite.config.js b/vite.config.js index 87fb7ef..a833fe4 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,5 +1,7 @@ import postcss from './postcss.config.js' import { svelte } from '@sveltejs/vite-plugin-svelte' + +// for importing from *.wasm files import wasm from 'vite-plugin-wasm' import path from 'path' diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 2510495..86a4053 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -7,12 +7,14 @@ edition = "2021" crate-type = ["cdylib", "rlib"] [features] -default = ["console_error_panic_hook"] +default = [ + "console_error_panic_hook" +] [dependencies] # js-sys = "0.3.57" -wasm-bindgen = "0.2.63" num-complex = "0.4.0" +wasm-bindgen = "0.2.63" # The `console_error_panic_hook` crate provides better debugging of panics by # logging them with `console.error`. This is great for development, but requires @@ -30,6 +32,10 @@ console_error_panic_hook = { version = "0.1.6", optional = true } # [dev-dependencies] # wasm-bindgen-test = "0.3.13" +# [dependencies.web-sys] +# version = "0.3.57" +# features = ["console"] + [profile.release] # Tell `rustc` to optimize for small code size. opt-level = "s" diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 0c14732..2b4ea82 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -46,7 +46,7 @@ impl Mandelbrot { /// * `rx` - Right coordinate of x 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, w: u16, h: u16, len: usize) { // total width of x axis (complex plane) let xwidth = rx - lx; @@ -64,10 +64,10 @@ impl Mandelbrot { // x display, y display let (mut xd, mut yd); - for i in 0..(w * h) { - xd = (i % w) as f64; - yd = (i / w) as f64; - self.pixels[i as usize] = check_series(lx + xd / scale, ty - yd / scale); + for i in 0..len { + xd = ((i as u16) % w) as f64; + yd = ((i as u16) / w) as f64; + self.pixels[i] = check_series(lx + xd / scale, ty - yd / scale); } } @@ -75,6 +75,10 @@ impl Mandelbrot { self.pixels.as_ptr() } + /*pub fn stats(&self) -> usize { + self.pixels.iter().filter(|p| **p == IS_IN).count() + }*/ + pub fn scale2x() { unimplemented!(); }