mandelbrot

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2018 License: MIT Imports: 0 Imported by: 0

README

go-mandelbrot

Mandelbrot fractal in Go

Documentation

Overview

Package mandelbrot provides functions for generating a Mandelbrot set.

Example

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

package main

import (
	"fmt"

	mandelbrot "github.com/t-pwk/go-mandelbrot"
)

func main() {
	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 (ElephantValley)

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

package main

import (
	"fmt"

	mandelbrot "github.com/t-pwk/go-mandelbrot"
)

func main() {
	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

Constants

View Source
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
)

Variables

This section is empty.

Functions

func Iter

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

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.

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

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