@@ -214,26 +214,28 @@ impl WorldView {
214
214
ctx. set_stroke_style_str ( "red" ) ;
215
215
ctx. begin_path ( ) ;
216
216
for obj in world. objects . iter ( ) {
217
+ let value = ( obj. velocity_x * obj. velocity_x + obj. velocity_y * obj. velocity_y ) . sqrt ( ) ;
217
218
let pos_x = obj. pos_x - self . center . 0 + self . canvas_width as f64 /2. ;
218
219
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) ; }
220
221
if ( display_values) {
221
222
ctx. set_font ( "20px Arial" ) ;
222
223
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) ;
224
225
}
225
226
}
226
227
ctx. stroke ( ) ;
227
228
ctx. set_stroke_style_str ( "green" ) ;
228
229
ctx. begin_path ( ) ;
229
230
for obj in world. objects . iter ( ) {
231
+ let value = ( world. gravity_x * world. gravity_x + world. gravity_y * world. gravity_y ) . sqrt ( ) ;
230
232
let pos_x = obj. pos_x - self . center . 0 + self . canvas_width as f64 /2. ;
231
233
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) ; }
233
235
if ( display_values) {
234
236
ctx. set_font ( "20px Arial" ) ;
235
237
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. ) ;
237
239
}
238
240
}
239
241
ctx. stroke ( ) ;
0 commit comments