diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /graphics/pgf/base/source/SimpleDemoC.c |
Initial commit
Diffstat (limited to 'graphics/pgf/base/source/SimpleDemoC.c')
-rw-r--r-- | graphics/pgf/base/source/SimpleDemoC.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/graphics/pgf/base/source/SimpleDemoC.c b/graphics/pgf/base/source/SimpleDemoC.c new file mode 100644 index 0000000000..18e5889ad1 --- /dev/null +++ b/graphics/pgf/base/source/SimpleDemoC.c @@ -0,0 +1,42 @@ +#include <pgf/gd/interface/c/InterfaceFromC.h> +#include <math.h> + +static void fast_hello_world (pgfgd_SyntacticDigraph* graph, void* v) { + double angle = 6.28318530718 / graph->vertices.length; + double radius = pgfgd_tonumber(graph->options, "fast simple demo radius"); + + int i; + for (i = 0; i < graph->vertices.length; i++) { + pgfgd_Vertex* v = graph->vertices.array[i]; + v->pos.x = cos(angle*i) * radius; + v->pos.y = sin(angle*i) * radius; + } +} + +int luaopen_pgf_gd_examples_c_SimpleDemoC (struct lua_State *state) { + pgfgd_Declaration* d; + + // The main layout key + d = pgfgd_new_key ("fast simple demo layout"); + pgfgd_key_summary (d, "The C version of the hello world of graph drawing."); + pgfgd_key_algorithm (d, fast_hello_world, 0); + pgfgd_key_documentation (d, + "Just like the |SimpleDemo| algorithm, this algorithm arranges \ + the nodes of a graph in a circle (without paying heed to the sizes of the \ + nodes or to the edges). Its main purpose is to show how C code \ + can access the Lua representation of graphs. See \ + Section~\ref{section-algorithms-in-c} of the manual for detais."); + pgfgd_key_add_precondition (d, "connected"); + pgfgd_declare (state, d); + pgfgd_free_key (d); + + // The radius key + d = pgfgd_new_key ("fast simple demo radius"); + pgfgd_key_summary (d, "A radius value for the hello world of graph drawing"); + pgfgd_key_type (d, "length"); + pgfgd_key_initial (d, "1cm"); + pgfgd_declare (state, d); + pgfgd_free_key (d); + + return 0; +} |