// This is of course super slow due to using CoreGraphics
This is of course super slow due to using CoreGraphics
This is of course super slow due to using CoreGraphics
fn paint(&mut self, ctx: &mut PaintCtx, data: &AudioData, _env: &Env) {
        ctx.clear(Color::BLACK);
        let AudioData(data) = data;
        if data.is_empty() {
            return;
        }
        let size = ctx.size();
        let mut prev = data[0];
        let mut index = 0;
        let mut shape = BezPath::new();
        let num_points = data.len();
        let width = size.width;
        let step = ((num_points as f64) / width) as usize;
        while index < data.len() {
            let item = data[index];
            let f_index = index as f64;
            let x_coord = (f_index / data.len() as f64) * size.width;
            let y_coord = (prev as f64) * size.height / 2.0 + size.height / 2.0;
            shape.move_to(Point::new(x_coord, y_coord));
            let mut draw = |item| {
                let x2_coord = ((f_index + 1.0) / data.len() as f64) * size.width;
                let y2_coord = (item as f64) * size.height / 2.0 + size.height / 2.0;
                shape.line_to(Point::new(x2_coord, y2_coord));
            };
            draw(item);
            draw(-item);
            prev = item;
            index += step;
        }
        ctx.stroke(shape, &Color::RED, 3.0);
    }
fn paint ( & mut self , ctx : & mut PaintCtx , data : & AudioData , _env : & Env ) { ctx . clear ( Color :: BLACK ) ; let AudioData ( data ) = data ; if data . is_empty ( ) { return ; } let size = ctx . size ( ) ; let mut prev = data [ 0 ] ; let mut index = 0 ; let mut shape = BezPath :: new ( ) ; let num_points = data . len ( ) ; let width = size . width ; let step = ( ( num_points as f64 ) / width ) as usize ; while index < data . len ( ) { let item = data [ index ] ; let f_index = index as f64 ; let x_coord = ( f_index / data . len ( ) as f64 ) * size . width ; let y_coord = ( prev as f64 ) * size . height / 2.0 + size . height / 2.0 ; shape . move_to ( Point :: new ( x_coord , y_coord ) ) ; let mut draw = | item | { let x2_coord = ( ( f_index + 1.0 ) / data . len ( ) as f64 ) * size . width ; let y2_coord = ( item as f64 ) * size . height / 2.0 + size . height / 2.0 ; shape . line_to ( Point :: new ( x2_coord , y2_coord ) ) ; } ; draw ( item ) ; draw ( - item ) ; prev = item ; index += step ; } ctx . stroke ( shape , & Color :: RED , 3.0 ) ; }
This is of course super slow due to using CoreGraphics
This is of course super slow due to using CoreGraphics
&mut self
ctx
&mut PaintCtx
data
&AudioData
_env
&Env