The goFractal
library is a Go package for generating fractals. This library provides support for both PNG and GIF formats. You can specify the focus points and zoom level for more detailed fractals.
To install the package, run:
go get -u github.com/leorighi/goFractal
First, import the package in your Go file:
import "github.com/leorighi/goFractal"
Initialize a new Mandelbrot struct with your preferred dimensions:
m := &goFractal.Mandelbrot{
Width: 800,
Height: 800,
}
To generate a PNG image:
err := m.GeneratePNG("mandelbrot.png", 0.0, 0.0)
if err != nil {
return err
}
To generate a GIF animation:
err := m.GenerateGIF("output.gif", 30, -1.4017, 0.0, 0.20)
if err != nil {
// Handle error
}
Generates a PNG image file of the Mandelbrot fractal.
filename
: The name of the output PNG file.focusX
: X-coordinate of the focus point.focusY
: Y-coordinate of the focus point.
Returns an error if the operation fails.
func (m *Mandelbrot) GeneratePNG(filename string, focusX float64, focusY float64) error
Generates a GIF image file with animated zoom of the Mandelbrot fractal.
filename
: The name of the output GIF file.frames
: Number of frames in the animation.focusX
: X-coordinate of the focus point.focusY
: Y-coordinate of the focus point.zoomSpeed
: Zoom speed for animation.
Returns an error if the operation fails.
func (m *Mandelbrot) GenerateGIF(filename string, frames int, focusX float64, focusY float64, zoomSpeed float64) error
Feel free to contribute to this project.