view_sphere/
view_sphere.rs

1use fdg_sim::{petgraph::graph::NodeIndex, ForceGraph, ForceGraphHelper};
2
3#[macroquad::main("Force Graph Sphere Demo")]
4async fn main() {
5    let mut graph: ForceGraph<(), ()> = ForceGraph::default();
6    let mut indices: Vec<NodeIndex> = Vec::new();
7
8    let height = 10;
9    let width = 50;
10
11    for x in 0..width {
12        for y in 0..height {
13            indices.push(graph.add_force_node(format!("x: {x}, y: {y}"), ()));
14        }
15    }
16
17    let top = graph.add_force_node("top", ());
18    let bottom = graph.add_force_node("bottom", ());
19
20    for y in 0..height {
21        for x in 0..width {
22            if x != 0 {
23                graph.add_edge(indices[(width * y) + x], indices[((width * y) + x) - 1], ());
24            }
25
26            if y != 0 {
27                graph.add_edge(indices[(width * y) + x], indices[(width * (y - 1)) + x], ());
28            }
29        }
30
31        // cylinder
32        graph.add_edge(indices[(width * y) + (width - 1)], indices[(width * y)], ());
33    }
34
35    for x in 0..width {
36        graph.add_edge(indices[(width * (height - 1)) + x], top, ());
37        graph.add_edge(indices[x], bottom, ());
38    }
39
40    fdg_macroquad::run_window(&graph).await;
41}