Skip to content

senutpal/fplot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fplot

A function plotter built with SDL3 and TinyExpr

Features

  • Plot any mathematical expression with variable x
  • Real-time rendering with SDL3
  • Automatic discontinuity detection
  • Grid and axis display
  • Support for complex expressions

Prerequisites

Windows

  • GCC (MinGW or similar)
  • SDL3 library installed at C:\SDL3\ (or update Makefile paths)

Linux

sudo apt-get install libsdl3-dev  # Ubuntu/Debian
sudo dnf install SDL3-devel       # Fedora

macOS

brew install sdl3

Building

Quick Build (Windows)

gcc -Wall -Wextra plot.c tinyexpr.c -IC:\SDL3\include -LC:\SDL3\lib -lSDL3 -lm -o plot.exe

Using Makefile

# 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

Usage

# Windows
set PATH=C:\SDL3\bin;%PATH%
plot.exe "sin(x)"

# Linux/Mac
./plot "sin(x)"

Example Expressions

./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))"

Supported Functions

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

Controls

  • Close Window - Click the X button or press Alt+F4

Configuration

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 resolution

Project Structure

function-plotter/
├── plot.c          # Main application code
├── tinyexpr.c      # TinyExpr library source
├── tinyexpr.h      # TinyExpr library header
├── Makefile        # Build configuration
└── README.md       # This file

How It Works

  1. Expression Parsing: TinyExpr compiles the mathematical expression
  2. Coordinate Mapping: Converts mathematical coordinates to screen pixels
  3. Plotting: Evaluates the function at small intervals and draws lines
  4. Discontinuity Detection: Skips drawing when function has large jumps
  5. Rendering: SDL3 renders the grid, axes, and function curve

Limitations

  • 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

Credits

  • SDL3 - Simple DirectMedia Layer
  • TinyExpr - Mathematical expression parser by Lewis Van Winkle

About

a tiny function plotter for the terminal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages