Skip to main content

wisp_storybook/stories/
s_graphics_arc.rs

1//! Story: arc + annular sector SDF primitives (M-VEC.20 / AUT-224).
2//!
3//! Six samples in a 3×2 grid:
4//!   * filled disc (full angular span, `r_inner = 0`),
5//!   * pie slice (90° wedge),
6//!   * full donut (`r_inner > 0`, full angular span),
7//!   * annular sector (partial donut),
8//!   * thin stroked arc via `draw_arc` (chart gauge needle / tick),
9//!   * semicircular gauge-style arc with thicker stroke.
10
11use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, PI, TAU};
12
13use glam::Vec2;
14use wisp::application::Application;
15use wisp::{Color, Fill, Graphics, Stage};
16
17use crate::story::Story;
18
19pub fn story() -> Story {
20    Story {
21        id: "graphics-arc",
22        category: "Graphics",
23        title: "Arc + annular sector",
24        milestone: "M-VEC.20",
25        writeup: include_str!("writeups/graphics_arc.md"),
26        build,
27        tick: None,
28    }
29}
30
31fn build(_app: &Application, stage: &mut Stage) {
32    let mut g = Graphics::new();
33
34    // Layout: 3 columns × 2 rows in NDC [-1, 1].
35    let col_x = [-0.66, 0.0, 0.66];
36    let row_y = [0.5, -0.5];
37    let radius = 0.22;
38
39    // (0, 0): full filled disc — pie slice with span = 2π.
40    g.fill(Fill::Solid(Color::rgba_u8(80, 200, 255, 255)));
41    g.draw_annular_sector(Vec2::new(col_x[0], row_y[0]), 0.0, radius, 0.0, TAU);
42
43    // (1, 0): 90° pie slice (wedge from 0 to π/2).
44    g.fill(Fill::Solid(Color::rgba_u8(255, 200, 80, 255)));
45    g.draw_annular_sector(Vec2::new(col_x[1], row_y[0]), 0.0, radius, 0.0, FRAC_PI_2);
46
47    // (2, 0): full donut (r_inner > 0, full span).
48    g.fill(Fill::Solid(Color::rgba_u8(160, 100, 220, 255)));
49    g.draw_annular_sector(Vec2::new(col_x[2], row_y[0]), 0.12, radius, 0.0, TAU);
50
51    // (0, 1): annular sector — partial donut (≈ 270° span).
52    g.fill(Fill::Solid(Color::rgba_u8(120, 220, 140, 255)));
53    g.draw_annular_sector(
54        Vec2::new(col_x[0], row_y[1]),
55        0.12,
56        radius,
57        FRAC_PI_4,
58        FRAC_PI_4 + TAU * 0.75,
59    );
60
61    // (1, 1): thin stroked arc — gauge needle band style.
62    g.fill(Fill::Solid(Color::rgba_u8(255, 100, 80, 255)));
63    g.draw_arc(
64        Vec2::new(col_x[1], row_y[1]),
65        radius,
66        -FRAC_PI_4,
67        FRAC_PI_4,
68        0.025,
69    );
70
71    // (2, 1): semicircular gauge — half circle with thick stroke.
72    g.fill(Fill::Solid(Color::rgba_u8(80, 220, 200, 255)));
73    g.draw_arc(Vec2::new(col_x[2], row_y[1]), radius, PI, TAU, 0.05);
74
75    let _ = stage.add_child(stage.root(), g);
76}