A C-based function graph plotter that renders mathematical expressions into PPM images and generates an animated video using ffmpeg.
The project supports runtime-defined mathematical functions using the TinyExpr expression parser.
- Plot mathematical functions given as strings (e.g.
sin(x),x^2,sqrt(x^2+1)). - Runtime expression parsing using TinyExpr.
- Direct pixel-level rendering using the PPM (P6) image format.
- Animated horizontal zoom-out effect along the x-axis.
- Automatic MP4 video generation via ffmpeg.
- Cleans up intermediate PPM frames automatically.
- Minimal dependencies, fully written in C (C99).
- C compiler (GCC or Clang, C99 compatible)
- ffmpeg
- TinyExpr
tinyexpr.ctinyexpr.h
TinyExpr is released under the zlib license and is included directly in this project.
-
Expression Parsing
- The function is provided as a string.
- TinyExpr parses and compiles the expression once.
- The variable
xis bound at evaluation time.
-
Coordinate Mapping
- Mathematical coordinates
(x, y)are mapped to pixel coordinates(px, py). - The x-range expands frame-by-frame, creating a horizontal zoom-out effect.
- The y-range remains fixed to avoid visual bouncing.
- Mathematical coordinates
-
Rendering
- Each frame is rendered into a PPM image buffer.
- X and Y axes are drawn when visible.
- The function curve is plotted in pixel space.
-
Video Generation
- All frames are combined into an MP4 video using ffmpeg.
- Temporary PPM files are deleted automatically.
Thanks to TinyExpr, the following are supported:
- Arithmetic operators:
+ - * / ^ - Math functions:
sin,cos,tansqrt,log,lnabs,exp, etc.
- Constants:
pi,e - Variable binding:
x
sin(x)
x^2
sqrt(x^2 + 1)
sin(x) * exp(-0.1*x)
output.mp4
Example animation plotting sinc(x) with horizontal zoom-out.