fractals

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IFS_FXN_INDEX_A           = 0
	IFS_FXN_INDEX_B           = 1
	IFS_FXN_INDEX_C           = 2
	IFS_FXN_INDEX_D           = 3
	IFS_FXN_INDEX_E           = 4
	IFS_FXN_INDEX_F           = 5
	IFS_FXN_INDEX_PROBABILITY = 6
	// The number of variables in each set of the iterated function system.
	IFS_FXN_VARIABLES_COUNT = int(7)
)
View Source
const (
	JULIA_SET_MAX_ITERATIONS         = 500_000
	JULIA_SET_DEFAULT_ITERATIONS     = 250
	JULIA_SET_DEFAULT_COLOR_PALETTE  = "multi_colored"
	JULIA_SET_DEFAULT_C              = -0.5 + 0.6i
	JULIA_SET_DEFAULT_BAIL_OUT       = 2
	JULIA_SET_DEFAULT_REGION         = "-1.5, -1.5, 3, 3"
	JULIA_SET_DEFAULT_SERIES_TYPE    = "classic"
	JULIA_SET_DEFAULT_VARIABLES_TEXT = "i=3+0i, k=0.0-0.01i"
	JULIA_SET_DEFAULT_VARIABLE_I     = 3 + 0i
	JULIA_SET_DEFAULT_VARIABLE_K     = 0.0 - 0.01i
)
View Source
const (
	MAX_DELTA = 1e-14
)

Variables

View Source
var (
	HOPALONG_TYPES = map[string]func(props *Hopalong, xIn, yIn float64) (xOut, yOut float64){
		"classic_bm":      classic_barry_martin_fractal,
		"positive_bm":     positive_barry_martin_fractal,
		"additive_bm":     additive_barry_martin_fractal,
		"gingerbread_man": gingerbread_man_fractal,
	}
)
View Source
var (
	JULIA_SET_SERIES = map[string]func(*JuliaSet) func(complex128) complex128{
		"classic": func(props *JuliaSet) func(complex128) complex128 {
			return func(z complex128) complex128 { return z*z + props.C }
		},
		"lace": func(props *JuliaSet) func(complex128) complex128 {
			return func(z complex128) complex128 {
				i := props.GetVaraible('i', JULIA_SET_DEFAULT_VARIABLE_I)
				return (i*cmplx.Pow(z, -3) + 1010) / (props.C*i*cmplx.Pow(z, -6) + 3301*z)
			}
		},
		"phoenix": func(props *JuliaSet) func(complex128) complex128 {
			return func(z complex128) complex128 {
				k := props.GetVaraible('k', JULIA_SET_DEFAULT_VARIABLE_K)
				return z*z + props.C + k*props.zPrev
			}
		},
		"csin":       func(props *JuliaSet) func(complex128) complex128 { return cTrig(props, cmplx.Sin) },
		"ccos":       func(props *JuliaSet) func(complex128) complex128 { return cTrig(props, cmplx.Cos) },
		"ctan":       func(props *JuliaSet) func(complex128) complex128 { return cTrig(props, cmplx.Tan) },
		"abs_sin4":   func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Sin) },
		"abs_cos4":   func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Cos) },
		"abs_tan4":   func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Tan) },
		"abs_cot4":   func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Cot) },
		"abs_sinh4":  func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Sinh) },
		"abs_cosh4":  func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Cosh) },
		"abs_tanh4":  func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Tanh) },
		"abs_asinh4": func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Asinh) },
		"abs_acosh4": func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Acosh) },
		"abs_atanh4": func(props *JuliaSet) func(complex128) complex128 { return absTrig(props, cmplx.Atanh) },
	}
)

Functions

func GetIFSColors

func GetIFSColors(txt string, count int) []color.RGBA

Retrieves a slice of colors for the IFS.

func GetIFSVariables

func GetIFSVariables(txt string) ([][IFS_FXN_VARIABLES_COUNT]float64, error)

Retrieves a comma-separated list of the variables for each set of the IFS.

func IsValidJuliaSetSeriesFunction

func IsValidJuliaSetSeriesFunction(txt string) bool

Checks if a function name exists in the set of JULIA_SET_SERIES names.

func ParseJuliaSetVariables

func ParseJuliaSetVariables(txt string) (map[rune]complex128, error)

Converts a comma-separated list of variable assignments to a map of runes and complex numbers.

func ParseLSystemPosition

func ParseLSystemPosition(txt string, width, height float64) (x, y float64, err error)

Retrieves the cartesian position of a point given a position.

func ParseLindenmayerRules

func ParseLindenmayerRules(txt string) (map[rune]string, error)

Converts a comma-separated list of rewrite rules to a map of variable and rewrite string.

Types

type CantorDust

type CantorDust struct {
	Width           int
	Height          int
	Color           color.RGBA
	UseRandomColors bool
	Iterations      int
	Background      color.RGBA
}

Properties of a Cantor set image.

func (*CantorDust) WriteImage

func (props *CantorDust) WriteImage(output io.Writer)

Writes the Cantor dust image to the given output.

type CantorSet

type CantorSet struct {
	Width           int
	Height          int
	Color           color.RGBA
	UseRandomColors bool
	LineHeight      float64
	Iterations      int
	Background      color.RGBA
}

Properties of a Cantor set image.

func (*CantorSet) WriteImage

func (props *CantorSet) WriteImage(output io.Writer)

Writes the Cantor set image to the given output.

type Hopalong

type Hopalong struct {
	Width           int
	Height          int
	Color           color.RGBA
	UseRandomColors bool
	A               float64
	B               float64
	C               float64
	D               float64
	X               float64
	Y               float64
	Type            string
	Scale           float64
	Resolution      int
	Background      color.RGBA
}

Properties of a Hopalong image.

func (*Hopalong) WriteImage

func (props *Hopalong) WriteImage(output io.Writer)

Writes the Hopalong image to the given output.

type IteratedFunctionSystem

type IteratedFunctionSystem struct {
	Width      int
	Height     int
	Colors     []color.RGBA
	Iterations int
	X          float64
	Y          float64
	Scale      float64
	Focus      bool
	Variables  [][IFS_FXN_VARIABLES_COUNT]float64
	Background color.RGBA
}

Properties of an iterated function system (IFS) image.

func (*IteratedFunctionSystem) WriteImage

func (props *IteratedFunctionSystem) WriteImage(output io.Writer) error

Writes the IFS image to the given output.

type JuliaSet

type JuliaSet struct {
	Width              int
	Height             int
	ColorPalette       helpers.ColorPalette
	MaxIterations      int
	C                  complex128
	Variables          map[rune]complex128
	BailOut            float64
	Region             helpers.Rect
	SeriesFunctionName string
	Background         color.RGBA
	// contains filtered or unexported fields
}

Properties of a Julia set image.

func (*JuliaSet) GetVaraible

func (props *JuliaSet) GetVaraible(c rune, defaultValue complex128) complex128

Retrieves the value of a variable and returns a default value if the variable doesn't exist.

func (*JuliaSet) WriteImage

func (props *JuliaSet) WriteImage(output io.Writer) error

Writes the Julia set image to the given output.

type LindenmayerSystem

type LindenmayerSystem struct {
	Width                 int
	Height                int
	Axiom                 string
	Iterations            int
	RewriteRules          map[rune]string
	DrawSymbols           string
	SkipSymbols           string
	Angle                 float64
	Color                 color.RGBA
	UseRandomColors       bool
	Focus                 bool
	TurningAngle          float64
	Position              string
	LineWidth             float64
	LineLength            float64
	LineWidthIncrement    float64
	LineLengthScaleFactor float64
	TurningAngleIncrement float64
	Background            color.RGBA
}

func (*LindenmayerSystem) BuildGenerator

func (props *LindenmayerSystem) BuildGenerator() []rune

Builds the image generation string for this Lindenmayer system.

func (*LindenmayerSystem) WriteImage

func (props *LindenmayerSystem) WriteImage(output io.Writer) error

Writes the Lindenmayer system image to the given output.

type MandelbrotSet

type MandelbrotSet struct {
	Width         int
	Height        int
	ColorPalette  helpers.ColorPalette
	MaxIterations int
	M             float64
	BailOut       float64
	Region        helpers.Rect
	Background    color.RGBA
}

Properties of a Mandelbrot set image.

func (*MandelbrotSet) WriteImage

func (props *MandelbrotSet) WriteImage(output io.Writer) error

Writes the Mandelbrot set image to the given output.

type NewtonBasin

type NewtonBasin struct {
	Width            int
	Height           int
	ColorPalette     helpers.ColorPalette
	MaxIterations    int
	Polynomial       math_helpers.CmplxPolynomial
	BailOut          float64
	Region           helpers.Rect
	Background       color.RGBA
	UseDynamicColors bool
}

Properties of a Newton basin image.

func (*NewtonBasin) WriteImage

func (props *NewtonBasin) WriteImage(output io.Writer) error

Writes the Newton basin image to the given output.

type SierpinskiCarpet

type SierpinskiCarpet struct {
	Width           int
	Height          int
	Color           color.RGBA
	UseRandomColors bool
	Iterations      int
	Background      color.RGBA
}

Properties of a Sierpinski carpet image.

func (*SierpinskiCarpet) WriteImage

func (props *SierpinskiCarpet) WriteImage(output io.Writer)

Writes the Sierpinski carpet image to the given output.

type SierpinskiTriangle

type SierpinskiTriangle struct {
	Width           int
	Height          int
	Color           color.RGBA
	UseRandomColors bool
	Iterations      int
	Background      color.RGBA
}

Properties of a Sierpinski triangle image.

func (*SierpinskiTriangle) WriteImage

func (props *SierpinskiTriangle) WriteImage(output io.Writer)

Writes the Sierpinski triangle image to the given output.

type State

type State struct {
	Angle              float64
	LineWidth          float64
	LineLength         float64
	TurningAngle       float64
	SwapTurnDirections bool
	X                  float64
	Y                  float64
}

Represents a drawing state

Jump to

Keyboard shortcuts

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