@@ -214,26 +214,28 @@ impl WorldView {
214214 ctx. set_stroke_style_str ( "red" ) ;
215215 ctx. begin_path ( ) ;
216216 for obj in world. objects . iter ( ) {
217+ let value = ( obj. velocity_x * obj. velocity_x + obj. velocity_y * obj. velocity_y ) . sqrt ( ) ;
217218 let pos_x = obj. pos_x - self . center . 0 + self . canvas_width as f64 /2. ;
218219 let pos_y = obj. pos_y - self . center . 1 + self . canvas_height as f64 /2. ;
219- canvas_arrow ( & ctx, pos_x, pos_y, pos_x+obj. velocity_x /scale, pos_y+obj. velocity_y /scale) ;
220+ if ( value != 0. ) { canvas_arrow ( & ctx, pos_x, pos_y, pos_x+obj. velocity_x /scale, pos_y+obj. velocity_y /scale) ; }
220221 if ( display_values) {
221222 ctx. set_font ( "20px Arial" ) ;
222223 ctx. set_fill_style_str ( "red" ) ;
223- ctx. fill_text ( & format ! ( "{:.2}" , ( obj . velocity_x * obj . velocity_x + obj . velocity_y * obj . velocity_y ) . sqrt ( ) ) , pos_x , pos_y) ;
224+ ctx. fill_text ( & format ! ( "{:.2}" , value ) , pos_x , pos_y) ;
224225 }
225226 }
226227 ctx. stroke ( ) ;
227228 ctx. set_stroke_style_str ( "green" ) ;
228229 ctx. begin_path ( ) ;
229230 for obj in world. objects . iter ( ) {
231+ let value = ( world. gravity_x * world. gravity_x + world. gravity_y * world. gravity_y ) . sqrt ( ) ;
230232 let pos_x = obj. pos_x - self . center . 0 + self . canvas_width as f64 /2. ;
231233 let pos_y = obj. pos_y - self . center . 1 + self . canvas_height as f64 /2. ;
232- canvas_arrow ( & ctx, pos_x, pos_y, pos_x+world. gravity_x * 5. /scale, pos_y+world. gravity_y * 5. /scale) ;
234+ if ( value != 0. ) { canvas_arrow ( & ctx, pos_x, pos_y, pos_x+world. gravity_x * 5. /scale, pos_y+world. gravity_y * 5. /scale) ; }
233235 if ( display_values) {
234236 ctx. set_font ( "20px Arial" ) ;
235237 ctx. set_fill_style_str ( "green" ) ;
236- ctx. fill_text ( & format ! ( "{:.2}" , ( world . gravity_x * world . gravity_x + world . gravity_y * world . gravity_y ) . sqrt ( ) ) , pos_x , pos_y+20. ) ;
238+ ctx. fill_text ( & format ! ( "{:.2}" , value ) , pos_x , pos_y+20. ) ;
237239 }
238240 }
239241 ctx. stroke ( ) ;
0 commit comments