Skip to main content

wisp_storybook/stories/
s_path_stroke.rs

1//! Story: path stroke (M-VEC.10 / AUT-62).
2//!
3//! Three flavors of stroked path:
4//!
5//! - Straight arrow (`Callout::arrow_to`).
6//! - Bezier curve (quad) — adaptive flattening produces enough
7//!   segments for a smooth visual.
8//! - Polyline freehand stroke.
9
10use glam::Vec2;
11use wisp::application::Application;
12use wisp::{Callout, Color, PathBuilder, Stage};
13
14use crate::story::Story;
15
16pub fn story() -> Story {
17    Story {
18        id: "path-stroke",
19        category: "Vector",
20        title: "Path stroke + arrows",
21        milestone: "M-VEC.10 / AUT-62",
22        writeup: include_str!("writeups/path_stroke.md"),
23        build,
24        tick: None,
25    }
26}
27
28fn build(_app: &Application, stage: &mut Stage) {
29    let root = stage.root();
30
31    // Arrow — Callout helper.
32    let arrow = Callout::arrow_to(
33        Vec2::new(-0.7, 0.5),
34        Vec2::new(-0.1, 0.0),
35        0.025,
36        Color::rgba_u8(255, 230, 80, 255),
37    );
38    let _ = stage.add_child(root, arrow);
39
40    // Quadratic Bezier curve.
41    let curve = PathBuilder::new()
42        .move_to(Vec2::new(-0.6, -0.4))
43        .quad_to(Vec2::new(0.0, 0.6), Vec2::new(0.6, -0.4))
44        .build()
45        .stroke_to_graphics(0.025, Color::rgba_u8(80, 200, 240, 255), 0.005);
46    let _ = stage.add_child(root, curve);
47
48    // Polyline freehand stroke.
49    let freehand = PathBuilder::new()
50        .move_to(Vec2::new(0.1, 0.5))
51        .line_to(Vec2::new(0.3, 0.6))
52        .line_to(Vec2::new(0.5, 0.4))
53        .line_to(Vec2::new(0.7, 0.55))
54        .line_to(Vec2::new(0.85, 0.3))
55        .build()
56        .stroke_to_graphics(0.02, Color::rgba_u8(220, 110, 80, 255), 0.005);
57    let _ = stage.add_child(root, freehand);
58}