MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / main

Function main

draw/examples/dashed_line.rs:10–55  ·  view source on GitHub ↗

Draws a dashed line

()

Source from the content-addressed store, hash-verified

8/// Draws a dashed line
9///
10pub 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}

Callers

nothing calls this directly

Calls 15

with_2d_graphicsFunction · 0.85
create_drawing_windowFunction · 0.85
clear_canvasMethod · 0.80
canvas_heightMethod · 0.80
center_regionMethod · 0.80
line_widthMethod · 0.80
new_dash_patternMethod · 0.80
dash_offsetMethod · 0.80
dash_lengthMethod · 0.80
stroke_colorMethod · 0.80
new_pathMethod · 0.80
rectMethod · 0.80

Tested by

no test coverage detected