MCPcopy Create free account
hub / github.com/GreycLab/CImg / main

Function main

examples/plotter1d.cpp:50–73  ·  view source on GitHub ↗

Main procedure ----------------

Source from the content-addressed store, hash-verified

48// Main procedure
49//----------------
50int main(int argc,char **argv) {
51
52 // Read command line argument.
53 cimg_usage("Simple plotter of mathematical formulas");
54 const char *const formula = cimg_option("-f","sin(x/8) % cos(2*x)","Formula to plot");
55 const float x0 = cimg_option("-x0",-5.0f,"Minimal X-value");
56 const float x1 = cimg_option("-x1",5.0f,"Maximal X-value");
57 const int resolution = cimg_option("-r",1024,"Plot resolution");
58 const unsigned int nresolution = resolution>1?resolution:1024;
59 const unsigned int plot_type = cimg_option("-p",1,"Plot type");
60 const unsigned int vertex_type = cimg_option("-v",1,"Vertex type");
61
62 // Create plot data.
63 CImg<double> values(4,nresolution,1,1,0);
64 const unsigned int r = nresolution - 1;
65 cimg_forY(values,X) values(0,X) = x0 + X*(x1 - x0)/r;
66 cimg::eval(formula,values).move_to(values);
67
68 // Display interactive plot window.
69 values.display_graph(formula,plot_type,vertex_type,"X-axis",x0,x1,"Y-axis");
70
71 // Quit.
72 return 0;
73}

Callers

nothing calls this directly

Calls 1

cimg_forYFunction · 0.70

Tested by

no test coverage detected