A function plotter built with SDL3 and TinyExpr
- Plot any mathematical expression with variable
x - Real-time rendering with SDL3
- Automatic discontinuity detection
- Grid and axis display
- Support for complex expressions
- GCC (MinGW or similar)
- SDL3 library installed at
C:\SDL3\(or update Makefile paths)
sudo apt-get install libsdl3-dev # Ubuntu/Debian
sudo dnf install SDL3-devel # Fedorabrew install sdl3gcc -Wall -Wextra plot.c tinyexpr.c -IC:\SDL3\include -LC:\SDL3\lib -lSDL3 -lm -o plot.exe# Build
make
# Build and run with default function (sin(x))
make run
# Build and run with custom function
make test EXPR="x^2"
# Clean build files
make clean
# Rebuild from scratch
make rebuild# Windows
set PATH=C:\SDL3\bin;%PATH%
plot.exe "sin(x)"
# Linux/Mac
./plot "sin(x)"./plot "sin(x)"
./plot "x^2"
./plot "cos(x)*exp(-x/5)"
./plot "tan(x)"
./plot "1/x"
./plot "x^3 - 4*x"
./plot "sqrt(abs(x))"
./plot "log(abs(x))"TinyExpr supports the following functions:
- Trigonometric:
sin,cos,tan,asin,acos,atan,atan2 - Hyperbolic:
sinh,cosh,tanh - Exponential/Logarithmic:
exp,log,log10,ln - Power:
pow,sqrt - Other:
abs,ceil,floor,round - Constants:
pi,e
- Close Window - Click the X button or press Alt+F4
Edit the following constants in plot.c to customize:
#define WIDTH 900 // Window width
#define HEIGHT 600 // Window height
#define X_MIN -10.0 // Minimum x value
#define X_MAX 10.0 // Maximum x value
#define Y_MIN -10.0 // Minimum y value
#define Y_MAX 10.0 // Maximum y value
#define STEP 0.01 // Plotting resolutionfunction-plotter/
├── plot.c # Main application code
├── tinyexpr.c # TinyExpr library source
├── tinyexpr.h # TinyExpr library header
├── Makefile # Build configuration
└── README.md # This file
- Expression Parsing: TinyExpr compiles the mathematical expression
- Coordinate Mapping: Converts mathematical coordinates to screen pixels
- Plotting: Evaluates the function at small intervals and draws lines
- Discontinuity Detection: Skips drawing when function has large jumps
- Rendering: SDL3 renders the grid, axes, and function curve
- Plotting range is fixed (-10 to 10 on both axes)
- No zooming or panning
- No multiple function support
- Functions must be continuous or have proper discontinuity handling
- SDL3 - Simple DirectMedia Layer
- TinyExpr - Mathematical expression parser by Lewis Van Winkle