Draws a dashed line
()
| 8 | /// Draws a dashed line |
| 9 | /// |
| 10 | pub fn main() { |
| 11 | with_2d_graphics(|| { |
| 12 | // Create a window |
| 13 | let canvas = create_drawing_window("Dashed line"); |
| 14 | |
| 15 | let mut offset = 0.0; |
| 16 | loop { |
| 17 | canvas.draw(|gc| { |
| 18 | gc.clear_canvas(Color::Rgba(1.0, 1.0, 1.0, 1.0)); |
| 19 | |
| 20 | // Set up the canvas |
| 21 | gc.canvas_height(1000.0); |
| 22 | gc.center_region(0.0, 0.0, 1000.0, 1000.0); |
| 23 | |
| 24 | gc.line_width(8.0); |
| 25 | gc.new_dash_pattern(); |
| 26 | gc.dash_offset(offset % 60.0); |
| 27 | gc.dash_length(20.0); |
| 28 | gc.dash_length(10.0); |
| 29 | gc.dash_length(20.0); |
| 30 | gc.dash_length(10.0); |
| 31 | gc.stroke_color(Color::Rgba(0.0, 0.0, 0.6, 1.0)); |
| 32 | |
| 33 | gc.new_path(); |
| 34 | gc.rect(100.0, 100.0, 900.0, 900.0); |
| 35 | gc.stroke(); |
| 36 | |
| 37 | gc.new_path(); |
| 38 | gc.move_to(200.0, 200.0); |
| 39 | gc.line_to(800.0, 800.0); |
| 40 | gc.stroke(); |
| 41 | |
| 42 | gc.new_path(); |
| 43 | gc.circle(300.0, 700.0, 100.0); |
| 44 | gc.stroke(); |
| 45 | |
| 46 | gc.new_path(); |
| 47 | gc.circle(700.0, 300.0, 100.0); |
| 48 | gc.fill(); |
| 49 | }); |
| 50 | |
| 51 | offset += 1.0; |
| 52 | thread::sleep(Duration::from_nanos(1_000_000_000 / 60)); |
| 53 | } |
| 54 | }); |
| 55 | } |
nothing calls this directly
no test coverage detected