go-mandelbrot: github.com/T-PWK/go-mandelbrot Index | Examples | Files

package mandelbrot

import "github.com/T-PWK/go-mandelbrot"

Package mandelbrot provides functions for generating a Mandelbrot set.

Example of a small Mandelbrot set composed of 400 numbers (20 x 20) with 9 set to maximum iteration

Code:

m := mandelbrot.Mandelbrot(mandelbrot.Min, mandelbrot.Max, 20, 20, 9)

for i := range m {
    fmt.Println(m[i])
}

Output:

[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 0 1 1 1 1 1 1 2 4 3 2 1 0 0 0 0]
[0 0 0 0 1 1 1 1 1 2 2 3 5 9 3 2 1 1 0 0]
[0 0 0 1 1 1 1 1 2 2 3 4 9 9 5 3 2 1 1 0]
[0 0 1 1 1 1 1 2 3 4 9 9 9 9 9 6 9 2 1 1]
[0 1 1 1 1 2 3 3 4 6 9 9 9 9 9 9 9 3 1 1]
[0 1 1 2 3 9 5 6 6 9 9 9 9 9 9 9 9 3 1 1]
[0 2 2 3 3 8 9 9 9 9 9 9 9 9 9 9 9 3 2 1]
[0 3 4 5 9 9 9 9 9 9 9 9 9 9 9 9 9 3 2 1]
[0 3 4 5 9 9 9 9 9 9 9 9 9 9 9 9 9 3 2 1]
[0 2 2 3 3 8 9 9 9 9 9 9 9 9 9 9 9 3 2 1]
[0 1 1 2 3 9 5 6 6 9 9 9 9 9 9 9 9 3 1 1]
[0 1 1 1 1 2 3 3 4 6 9 9 9 9 9 9 9 3 1 1]
[0 0 1 1 1 1 1 2 3 4 9 9 9 9 9 6 9 2 1 1]
[0 0 0 1 1 1 1 1 2 2 3 4 9 9 5 3 2 1 1 0]
[0 0 0 0 1 1 1 1 1 2 2 3 5 9 3 2 1 1 0 0]
[0 0 0 0 0 1 1 1 1 1 1 2 4 3 2 1 0 0 0 0]
[0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

Example of a small Mandelbrot set composed of 400 numbers (20 x 20) with 9 set to maximum iteration presenting so called Elephant Valley

Code:

m := mandelbrot.Mandelbrot(0.25+0.05i, 0.35-0.05i, 20, 20, 9)

for i := range m {
    fmt.Println(m[i])
}

Output:

[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7 6]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 7 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 7]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8]
[9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8]

Index

Examples

Package Files

mandelbrot.go

Constants

const (
    // Min upper-left point for a default Mandelbrot fractal
    Min = -2 + 1.4i

    // Max lower-right point for a default Mandelbrot fractal
    Max = 0.8 - 1.4i
)

func Iter Uses

func Iter(p complex128, maxit uint) uint

Iter calculates iteration value for a given number point. The iteration value uses the following algorithm:

z = p;
repeat
  z = z*z + p
until |z| < 2;

It returns number of iteration at which the |z| < 2 condition is not met or the maximum iterations value.

func Mandelbrot Uses

func Mandelbrot(ul, lr complex128, h, w, maxit uint) [][]uint

Mandelbrot returns the Mandelbrot set of size (h,w). The set is generated between ul (upper-left) and lr (lower-right) points with the maximum number of iterations.

Updated 2018-09-28. Refresh now. Tools for package owners.