basic/
basic.rs

1use fdg_sim::{ForceGraph, ForceGraphHelper, Simulation, SimulationParameters};
2
3fn main() {
4    // initialize a graph
5    let mut graph: ForceGraph<(), ()> = ForceGraph::default();
6
7    // add nodes to it
8    let one = graph.add_force_node("one", ());
9    let two = graph.add_force_node("two", ());
10    let _three = graph.add_force_node("three", ());
11    graph.add_edge(one, two, ());
12
13    // create a simulation from the graph
14    let mut simulation = Simulation::from_graph(graph, SimulationParameters::default());
15
16    // your event/render loop
17    for frame in 0..50 {
18        // update the nodes positions based on force algorithm
19        simulation.update(0.035);
20
21        // render (print) your nodes new locations.
22        println!("---- frame {frame} ----");
23        for node in simulation.get_graph().node_weights() {
24            println!("\"{}\" - {:?}", node.name, node.location);
25        }
26    }
27}