Skip to content

This program takes a formula and plots the "heat" for any particular location

Notifications You must be signed in to change notification settings

arran4/heatplot

Repository files navigation

heatPlot

heatPlot is a Go tool for generating animated heatmaps (GIFs) from mathematical functions. It parses mathematical expressions involving variables x, y, and t (time), and renders them as a heatmap.

Installation

Ensure you have Go installed (Go 1.22+ recommended).

Clone the repository and install the dependencies:

git clone https://bitbucket.org/arran4/heatplot.git
cd heatplot
go mod tidy

Usage

There are three main commands available in the cmd directory:

1. heatPlot

Generates a heatmap GIF from a provided mathematical formula.

Build:

go build -o heatPlot cmd/heatPlot/main.go

Run:

./heatPlot [flags] "formula"

Flags:

  • -hcc: Heat colour count (default 126).
  • -speed: Duration between frames (default 100ms).
  • -pointSize: Scale of x/y steps (default 0.1).
  • -scale: Magnification (default 2).
  • -tlb: Time lower bound (start T, default 0).
  • -tub: Time upper bound (end T, default 100).
  • -size: Cartesian plane size (default 100, i.e., -100 to 100).
  • -outputFile: Output filename (default "./out.gif").
  • -footerText: Footer text (default "http://github.com/arran4/").

Example:

./heatPlot -outputFile="example.gif" "y = x * sin(t/10)"

2. heatPlotRandom

Generates random functions and renders one that meets certain "interestingness" criteria (complexity, movement).

Build:

go build -o heatPlotRandom cmd/heatPlotRandom/main.go

Run:

./heatPlotRandom [flags]

Flags:

Similar to heatPlot, with additional criteria for random generation.

3. whatFunctions

Lists all available single and double parameter functions supported by the parser.

Build:

go build -o whatFunctions cmd/whatFunctions/main.go

Run:

./whatFunctions

Formula Syntax

The parser supports:

  • Variables: x, y, t
  • Constants: Numbers
  • Operators: +, -, *, /, % (modulus), ^ (power)
  • Functions: sin, cos, tan, abs, max, min, pow, etc. (See whatFunctions for full list)
  • Grouping: ()

The parser generally expects an equation, often in the form LHS = RHS. The heatmap value is calculated as RHS - LHS.

Examples

Sine Wave

y = x * sin(t/10)

Sine Wave

Complex Interaction

y = x * sin(t/10) + y * cos(t/10)

Complex Interaction

Ripple

y = sin(sqrt(x^2 + y^2) - t/5)

Ripple

Interference

y = sin(x/10) + cos(y/10) * sin(t/10)

Interference

Development

Prerequisites

  • Go 1.22 or later
  • Make

Building

To regenerate the parser from calc.y:

make setup
make yacc

Testing

Run the tests:

go test ./...

About

This program takes a formula and plots the "heat" for any particular location

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •