Skip to content

MockingJay1710/C-function-plotter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C Graph Plotter (PPM + FFmpeg)

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.


✨ Features

  • 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).

📦 Dependencies

Required

  • C compiler (GCC or Clang, C99 compatible)
  • ffmpeg

Included

  • TinyExpr
    • tinyexpr.c
    • tinyexpr.h

TinyExpr is released under the zlib license and is included directly in this project.


🧠 How It Works

  1. Expression Parsing

    • The function is provided as a string.
    • TinyExpr parses and compiles the expression once.
    • The variable x is bound at evaluation time.
  2. 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.
  3. 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.
  4. Video Generation

    • All frames are combined into an MP4 video using ffmpeg.
    • Temporary PPM files are deleted automatically.

🧮 Supported Expressions

Thanks to TinyExpr, the following are supported:

  • Arithmetic operators: + - * / ^
  • Math functions:
    • sin, cos, tan
    • sqrt, log, ln
    • abs, exp, etc.
  • Constants: pi, e
  • Variable binding: x

Examples

sin(x)
x^2
sqrt(x^2 + 1)
sin(x) * exp(-0.1*x)

🎥 Demo

output.mp4

Example animation plotting sinc(x) with horizontal zoom-out.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages