mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
This commit refactors WebIDL code generation to walk over the fields of `FirstPassRecord` instead of walking the AST again. This helps remove redundancies like checking `is_chrome_only` as well as revisiting partial interfaces and such. This should make it more clear that the first pass's job is to walk the AST and collect all relevant information, while the codegen pass is purely about appending items to a `Program`. Additionally this refactoring will also soon be used to prepare different data structures for operation overloadings, avoiding the need to walk those ASTs twice.
29 lines
739 B
Rust
29 lines
739 B
Rust
extern crate wasm_bindgen;
|
|
extern crate web_sys;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
use web_sys::{CanvasRenderingContext2D, ImageData};
|
|
|
|
mod fractal;
|
|
use fractal::get_julia_set;
|
|
use fractal::complex::Complex;
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
pub type Uint8ClampedArray;
|
|
|
|
#[wasm_bindgen(constructor)]
|
|
pub fn new(arr: &[u8]) -> Uint8ClampedArray;
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn draw(ctx: &CanvasRenderingContext2D, width: u32, height: u32, real: f64, imaginary: f64) {
|
|
let c = Complex { real, imaginary };
|
|
let data = get_julia_set(width, height, c);
|
|
let uint8_array = Uint8ClampedArray::new(&data);
|
|
|
|
ctx.put_image_data(
|
|
&ImageData::with_data_and_sw_and_sh_with_sh(&data, width, height).unwrap(),
|
|
0.0, 0.0);
|
|
}
|