Skip to content

Polymath2603/mingraf

Repository files navigation

MinGraf

GitHub Release GitHub Stars GitHub Downloads Python License

Python library for mathematical visualizations and animations. Lighter than Manim, with live preview.

Installation

pip install pillow svgelements

LaTeX support (optional):

# Ubuntu/Debian
sudo apt install texlive-latex-extra dvisvgm

Quick Start

Basic Animation

from mingraf import *

scene = Scene(width=1280, height=720, fps=30)
circle = scene.add(Circle((0, 0), radius=1.5, color=BLUE, fill=True))

scene.play(circle.animate.shift(RIGHT * 2), duration=1.5)
scene.render("animation.mp4")

Mathematical Plotting

import numpy as np
from mingraf import *

scene = Scene(width=1280, height=720)

axes = scene.add(Axes(x_range=[-3, 3, 1], y_range=[-2, 2, 1]))
sin_graph = axes.plot(lambda x: np.sin(x), color=RED)
cos_graph = axes.plot(lambda x: np.cos(x), color=GREEN)

scene.add(sin_graph, cos_graph)

riemann = axes.get_riemann_rectangles(sin_graph, [0, np.pi], dx=0.5, color=YELLOW)
scene.add(riemann)
scene.render("functions.mp4")

Live Preview

from mingraf.live_preview import export as preview_export

with preview_export("output.mp4", preview=True) as scene:
    circle = scene.add(Circle((0, 0), radius=1.5, color=BLUE))
    scene.play(circle.animate.shift(RIGHT), duration=2)
    # Adjust parameters in real-time while preview runs

API

Shapes

Circle, Square, Rectangle, Line, Arrow, Dot, Triangle, Polygon, Ellipse

Math

Axes, NumberPlane, FunctionGraph, Surface, Brace, get_riemann_rectangles(), get_area()

Animations

animate.shift(), animate.scale(), animate.rotate(), Create, FadeIn, FadeOut, Transform

Scene

scene = Scene(width=640, height=480, fps=30, bg=(10, 10, 15))
scene.add(obj)                    # Add object
scene.remove(obj)                 # Remove object
scene.play(anim, duration=1)      # Play animation
scene.wait(seconds)               # Pause
scene.render("output.mp4")        # Render to file

Export

  • MP4scene.render("animation.mp4")
  • PNGscene.render("frame.png")
  • GIFscene.render("animation.gif")

MCP Server

python mingraf_mcp_server.py --port 8080

Examples

See the examples/ directory for complete examples.

Requirements

  • Python 3.9+
  • pillow, svgelements
  • ffmpeg (for MP4 export)

License

MIT

About

a minimal math graphing and animating library in python using Pillow & ffmpeg

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages