mandelbrot

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

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

Go to latest
Published: Feb 6, 2018 License: Unlicense Imports: 14 Imported by: 0

README

mandelbrot

Program to compute and colorize Mandelbrot and Julia sets.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePicture

func CreatePicture(coords Set, ramp []color.RGBA, width, height int, setColor color.RGBA) image.Image

CreatePicture draws an image.RGBA image.Image from the points created above.

func F

func F(z, c, exp complex128) complex128

F is the general form of the recurrence function `F = z^exp + c` .

func HexToRGBA

func HexToRGBA(hexColor string) color.RGBA

HexToRGBA converts a hex string in the form "RRGGBB" to a color.RGBA. The alpha component is always 255 (opaque).

func IsMemberJulia

func IsMemberJulia(z complex128, c complex128, iterations int) (bool, int)

IsMemberJulia runs the recurrent formula for the Julia set for the given number of iterations, and returns if the complex number `z` is in the set or not, as well as how many iterations it took to become 'infinity'.

func IsMemberMandelbrot

func IsMemberMandelbrot(c complex128, iterations int) (bool, int)

IsMemberMandelbrot runs the recurrent formula for the Mandelbrot set for the given number of iterations, and returns if the complex number `c` is in the set or not, as well as how many iterations it took to become 'infinity'.

func MakeRamp

func MakeRamp(stops []Stop) (ramp []color.RGBA)

MakeRamp uses a list of `Stop` to create a color ramp.

func OutputToJPG

func OutputToJPG(img image.Image, outputFilename string)

OutputToJPG writes an image.Image to the given output filename

func WriteConfig

func WriteConfig(c Config, filename string)

WriteConfig saves a config to file.

func WriteData

func WriteData(coords Set, filename string)

WriteData writes a Set to filename as a gob (go object serialization).

func WriteDefault

func WriteDefault()

WriteDefault is WriteConfig(NewConfig(), "default.json").

Types

type Action

type Action func(Job)

Action is a function which takes a complex number and does iterations to determine if the point is in a set (eg Mandelbrot set) or not. It also returns the number of iterations.

type BigJob

type BigJob struct {
	N          *big.Complex
	In         bool
	Iterations int
	Index      int
	X, Y       int
}

func NewBigJob

func NewBigJob(n complex128, index, x, y int) *BigJob

func (*BigJob) GetImageInfo

func (j *BigJob) GetImageInfo() (bool, int, int, int)

func (*BigJob) RunMandelbrot

func (j *BigJob) RunMandelbrot(iterations int)

This version runs about 30% faster than my "V1" version below. 3.3 mins vs 2.1 mins Math from https://randomascii.wordpress.com/2011/08/13/faster-fractals-through-algebra/

func (*BigJob) RunMandelbrotV1

func (j *BigJob) RunMandelbrotV1(iterations int)

type C128Job

type C128Job struct {
	N          complex128 // the complex number in question
	In         bool       // rough classification
	Iterations int        // number of iterations before becoming unbound
	Index      int        // for indexing/sorting in slice
	X, Y       int        // for making jpgs
}

Job contains information about a specific point in the mandelbrot set.

func NewC128Job

func NewC128Job(n complex128, index, x, y int) *C128Job

func (*C128Job) GetImageInfo

func (j *C128Job) GetImageInfo() (bool, int, int, int)

func (*C128Job) RunMandelbrot

func (j *C128Job) RunMandelbrot(iterations int)

type Config

type Config struct {
	CenterReal float64 `json:"center_real"`
	CenterImag float64 `json:"center_imag"`
	PlotWidth  float64 `json:"plot_width"`
	PlotHeight float64 `json:"plot_height"`
	XRes       int     `json:"x_res"`
	YRes       int     `json:"y_res"`
	Iterations int     `json:"iterations"`
	RampFile   string  `json:"ramp_file"`
	DataFile   string  `json:"data_file"`
	ImageFile  string  `json:"image_file"`
	SetColor   string  `json:"set_color"`
	JuliaReal  float64 `json:"julia_real"`
	JuliaImag  float64 `json:"julia_imag"`
}

Config is configuration info for the program, loaded from file.

func NewConfig

func NewConfig() Config

NewConfig gets a Config with reasonable default values.

func ReadConfig

func ReadConfig(filename string) (c Config)

ReadConfig loads a config file.

func (Config) DoJulia

func (c Config) DoJulia() bool

DoJulia is a convenince function to determine if the program should make a Julia set or not. If Julia[Real/Imag] is 0.0,0.0, then this returns false.

func (Config) GetJulia

func (c Config) GetJulia() complex128

GetJulia is a convenience function to get the Julia point as a complex128.

func (Config) String

func (c Config) String() string

type Job

type Job interface {
	// SetN(complex128)
	// PerformAction(Action)
	RunMandelbrot(int)
	GetImageInfo() (bool, int, int, int)
}

type Set

type Set []Job

Set is a list of *Job

func ReadData

func ReadData(filename string) (coords Set)

ReadData reads a Set from filename.

func (Set) Calculate

func (coords Set) Calculate(iterations int)

Calculate performs `action` on all the coordinates in a Set.

func (Set) CalculateProgress

func (coords Set) CalculateProgress(iterations int, progress *float64)

CalculateProgress performs `action` on all the coordinates in a Set. The progress can be obtained by providing the address of a float64 in which [0,1] will be written.

func (*Set) Initialize

func (coords *Set) Initialize(cfg Config)

Initialize sets up a MandelSet according to the configuration specified.

func (*Set) InitializeBig

func (coords *Set) InitializeBig(cfg Config)

type Stop

type Stop struct {
	Position int    `json:"position,omitempty"`
	Color    string `json:"color,omitempty"`
}

Stop represents a color stop and its position within a color ramp.

func ReadStops

func ReadStops(filename string) []Stop

ReadStops reads and returns the list of `Stop` from the json file.

func (Stop) RGBA

func (s Stop) RGBA() color.RGBA

RGBA converts the `Stop` to `color.RGBA`.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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