Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Apr 17, 2022
1 parent 7f9cc4d commit e69a21e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
9 changes: 8 additions & 1 deletion mandelbrot.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"folders":
[
{
"path": "."
"path": ".",
"folder_exclude_patterns": [/*"//src",*/ "//wasm"]
},
// {
// "path": "src"
// },
{
"path": "wasm"
}
],
"build_systems": [
Expand Down
2 changes: 2 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 8 additions & 2 deletions wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
14 changes: 9 additions & 5 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -64,17 +64,21 @@ 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);
}
}

pub fn pixels(&self) -> *const u8 {
self.pixels.as_ptr()
}

/*pub fn stats(&self) -> usize {
self.pixels.iter().filter(|p| **p == IS_IN).count()
}*/

pub fn scale2x() {
unimplemented!();
}
Expand Down

0 comments on commit e69a21e

Please sign in to comment.