blob: cfcd92fdd007957ac01b50a5ceabf875fe2231a2 [file] [log] [blame]
Austin Schuh8c794d52019-03-03 21:17:37 -08001/*
2 #
3 # File : plotter1d.cpp
4 # ( C++ source file )
5 #
6 # Description : A simple math formula plotter.
7 # This file is a part of the CImg Library project.
8 # ( http://cimg.eu )
9 #
10 # Copyright : David Tschumperle
11 # ( http://tschumperle.users.greyc.fr/ )
12 #
13 # License : CeCILL v2.0
14 # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
15 #
16 # This software is governed by the CeCILL license under French law and
17 # abiding by the rules of distribution of free software. You can use,
18 # modify and/ or redistribute the software under the terms of the CeCILL
19 # license as circulated by CEA, CNRS and INRIA at the following URL
20 # "http://www.cecill.info".
21 #
22 # As a counterpart to the access to the source code and rights to copy,
23 # modify and redistribute granted by the license, users are provided only
24 # with a limited warranty and the software's author, the holder of the
25 # economic rights, and the successive licensors have only limited
26 # liability.
27 #
28 # In this respect, the user's attention is drawn to the risks associated
29 # with loading, using, modifying and/or developing or reproducing the
30 # software by the user in light of its specific status of free software,
31 # that may mean that it is complicated to manipulate, and that also
32 # therefore means that it is reserved for developers and experienced
33 # professionals having in-depth computer knowledge. Users are therefore
34 # encouraged to load and test the software's suitability as regards their
35 # requirements in conditions enabling the security of their systems and/or
36 # data to be ensured and, more generally, to use and operate it in the
37 # same conditions as regards security.
38 #
39 # The fact that you are presently reading this means that you have had
40 # knowledge of the CeCILL license and that you accept its terms.
41 #
42*/
43
44// Include CImg library file and use its main namespace
45#include "CImg.h"
46using namespace cimg_library;
47
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}