This project is a Math Function Renderer that allows users to plot mathematical functions and visualize the resulting plots. The key components of the project include the Reader
, Expr
, and ExprParser
classes, forming the foundation of the rendering process. The expression tree is represented using vectors.
-
Bounds
- Represents the bounds of the plot.
-
Color
- Represents an RGB color value.
-
Exception
- Defines the
PlotException
class, which is thrown in case of fatal errors.
- Defines the
-
Expr
- Represents an expression node type.
-
ExprParser
- Parses an expression and builds an expression tree using vectors.
-
Fill
- Represents a fill directive, holding information about two function names, opacity, color, and fill type.
-
Function
- Represents a function to be plotted, including its name, expression, and associated RGB value.
-
Image
- Holds information about the image, including height, width, and an array of Color objects representing pixel RGB values.
-
Plot
- Combines information from other directives, such as bounds, functions, and fills, forming the basis of the plot.
-
Reader
- Reads a plot file to populate a
Plot
object.
- Reads a plot file to populate a
-
Renderer
- Renders a
Plot
object to produce anImage
.
- Renders a
- The project employs a modular design with separate classes for different components.
- Error handling is centralized in the
main.cpp
file, catching errors thrown in other classes.
Here is an example plot input file (input/example04.txt
):
Plot 0 -2.5 40 2.5 640 480
Function fn1 ( sin x )
Function fn2 ( * 1.6 ( cos x ) )
Color fn1 100 100 255
Color fn2 100 255 100
FillBetween fn1 fn2 0.4 128 0 200
This example produces the following image:
Explanation of the example plot:
- The
Plot
directive specifies the plot's region and image dimensions. - Two
Function
directives define functions to be plotted (fn1
andfn2
). - Two
Color
directives set the colors for each function. - The
FillBetween
directive fills the area betweenfn1
andfn2
with a specified color and opacity.
- Clone the repository.
- Compile and run the program using
main.cpp
. - Create your own plot input files or modify existing ones.
Feel free to explore and visualize various mathematical functions using this Math Function Renderer!