Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
elementary-plotlib/samples/plot-function.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (27 sloc)
1.04 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cmath> | |
| #include "elem/elem.h" | |
| using namespace elem; | |
| int main() { | |
| // The function FxLine generate a Path object based on a | |
| // mathematical function (x) -> f(x). | |
| Path sin_line = FxLine(0.0001, 8 * math::Tau(), [](double x) { return std::sin(x) / x; }); | |
| // Declare a plot object. | |
| Plot plot; | |
| // Add the line just created with a blue color and 1.5 pixel | |
| // line's width. | |
| plot.AddStroke(sin_line, color::Blue, 1.5); | |
| // Set Plot titles. | |
| plot.SetTitle("Function plot example"); | |
| plot.SetXAxisTitle("x variable"); | |
| plot.SetYAxisTitle("y variable"); | |
| // Show the plot on the screen. | |
| plot.Show(640, 480, WindowResize); | |
| // Add one more line corresponding to a different function. | |
| // Note that objects can be added after the plot is already | |
| // shown on the screen. | |
| Path cos_line = FxLine(0.8, 8 * math::Tau(), [](double x) { return std::cos(x) / x; }); | |
| plot.AddStroke(cos_line, color::Red, 1.5); | |
| // Wait until the window showing the plot is closed. | |
| plot.Wait(); | |
| return 0; | |
| } |