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

Function main

draw/examples/bounce.rs:58–91  ·  view source on GitHub ↗

Bouncing ball example

()

Source from the content-addressed store, hash-verified

56/// Bouncing ball example
57///
58pub fn main() {
59 // 'with_2d_graphics' is used to support operating systems that can't run event loops anywhere other than the main thread
60 with_2d_graphics(|| {
61 // Create a window with a canvas to draw on
62 let canvas = create_drawing_window("Bouncing balls");
63
64 // Generate some random balls
65 let mut balls = (0..256).into_iter().map(|_| Ball::random()).collect::<Vec<_>>();
66
67 // Animate them
68 loop {
69 // Update the balls for this frame
70 for ball in balls.iter_mut() {
71 ball.update();
72 }
73
74 // Render the frame
75 canvas.draw(|gc| {
76 gc.clear_canvas(Color::Rgba(0.6, 0.7, 0.8, 1.0));
77 gc.canvas_height(1000.0);
78 gc.center_region(0.0, 0.0, 1000.0, 1000.0);
79
80 for ball in balls.iter() {
81 gc.circle(ball.x as f32, ball.y as f32, ball.radius as f32);
82 gc.fill_color(ball.col);
83 gc.fill();
84 }
85 });
86
87 // Wait for the next frame
88 thread::sleep(Duration::from_nanos(1_000_000_000 / 60));
89 }
90 });
91}

Callers

nothing calls this directly

Calls 11

with_2d_graphicsFunction · 0.85
create_drawing_windowFunction · 0.85
mapMethod · 0.80
clear_canvasMethod · 0.80
canvas_heightMethod · 0.80
center_regionMethod · 0.80
circleMethod · 0.80
fill_colorMethod · 0.80
updateMethod · 0.45
drawMethod · 0.45
fillMethod · 0.45

Tested by

no test coverage detected