mandelbrot

package module
v0.0.0-...-fc40b91 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Intro

This project makes a mandelbrot image, or a gif of zooming in/out to a mandelbrot.

It is a toy go project for learning. My major learning objectives were:

  1. General go technical familiarity.
  2. Project layout
  3. Using Cobra for CLI generation

Test

go test ./...

If you are making changes and want to rewrite the golden test files, then add a flag:

go test -write-file

Run

go build cmd/main.go && ./main  new --filename foo.png

Gif

go build cmd/main.go && ./main gif  --height 45 --width 45 --maxIterations 10 --frames 10 --scaleIn .98 --x -1.5 --filename out.gif

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorRow

func ColorRow(img *image.RGBA, row, length uint16, xScale, yScale FloatFunction, colors []color.Color, wg *sync.WaitGroup)

ColorRow fills in one row of Mandelbrot values for an image

func EscapeIterations

func EscapeIterations(x0, y0 float64, maxIterations int) (iterations int)

EscapeIterations calculates how many iterations it takes for this point to escape Mandelbrot iteration, with a cap of maxIterations

func ExtentFromPoint

func ExtentFromPoint(x, y, xShift, yShift float64) (xMin, xMax, yMin, yMax float64)

ExtentFromPoint converts an x,y point + offsets in x and y into ranges of x and y values

func HasEscaped

func HasEscaped(x, y float64) bool

HasEscaped tells us whether a point has escaped under Mandelbrot iteration, ie it has length > 2

func NewPalette

func NewPalette(maxIterations uint8) []color.Color

NewPalette returns a list of colors to use as a palette

func Scale

func Scale(inputMin, inputMax, outputMin, outputMax float64) func(a float64) float64

Scale returns a scaling function clamped to a given range

func WritePng

func WritePng(img *image.RGBA, filename string)

WritePng writes an image to a filename Is there a good way to test this without deleting and recreating the file?

Types

type Drawer

type Drawer interface {
	Draw(minX, maxX, minY, maxY float64, colors []color.Color) *image.RGBA
	Gif(frames uint16, x, y, scaleIn float64, colors []color.Color) *gif.GIF
	SetSize(sizeX, sizeY uint16)
	SetIterations(maxIterations uint8)
}

type FloatFunction

type FloatFunction func(a float64) float64

FloatFunction is a takes a float64 and returns a float64.

type MandelbrotBuilder

type MandelbrotBuilder struct {
	SizeX, SizeY  uint16
	MaxIterations uint8
}

func (MandelbrotBuilder) Draw

func (bb MandelbrotBuilder) Draw(minX, maxX, minY, maxY float64, colors []color.Color) *image.RGBA

Draw draws a Mandelbrot image of a given size with a given domain and range

func (MandelbrotBuilder) Gif

func (bb MandelbrotBuilder) Gif(frames uint16, x, y, scaleIn float64, colors []color.Color) *gif.GIF

Gif returns the gif containing frames and delays for a mandelbrot animation

func (*MandelbrotBuilder) SetIterations

func (bb *MandelbrotBuilder) SetIterations(maxIterations uint8)

func (*MandelbrotBuilder) SetSize

func (bb *MandelbrotBuilder) SetSize(sizeX, sizeY uint16)

Directories

Path Synopsis
Package cli provides facilities for using the mandelbrot library via CLI.
Package cli provides facilities for using the mandelbrot library via CLI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL