gofra

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

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 19 Imported by: 0

README

gofra

gofra is simple fractal render library.

default fractal

Installation

To install gofra, simply run:

go get github.com/gitchander/gofra

Getting started console util

Сonsole rendering program exists in the directory gofra/cmd/gofra

It used package: cli.go

You will build console program:

$ cd gofra/cmd/gofra
$ go build
Make default

For make default file config:

$ ./gofra default

in this case the file will be created fractal.json

Render fractal

For render first fractal, run:

$ ./gofra draw

created image file fractal.png

$ ./gofra --image my_fractal.png draw

created image file my_fractal.png

you can watch it in any viewer program.

Scale fractal
$ ./gofra scale 2

changed scale factor in configuration file. for make fractal image you will render again.

Or you can run:

$ ./gofra --render scale 2

Also it makes render.

Move position

For move center position used command move [w,a,s,d], where w,a,s,d are diractions like arrows. The directions encodes with next characters:

'w' -> y += 0.5 // move up
'a' -> x -= 0.5 // move left
's' -> y -= 0.5 // move down
'd' -> x += 0.5 // move right

Examples:

./gofra move a
# x = -0.5, y = 0
./gofra move wd
# x = 0.5, y = 0.5
./gofra move sa
# x = -0.5, y = -0.5
./gofra move dds
# x = 1.0, y = -0.5

Images

fractal-1 fractal-2 fractal-3 fractal-4 fractal-5 fractal-6 fractal-7 fractal-8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	ImageSize: Size{
		Width:  512,
		Height: 512,
	},
	FractalInfo: FractalInfo{
		Formula: FormulaMandelbrot,
		Location: Location{
			Center: Complex{
				Re: 0,
				Im: 0,
			},
			Radius:   2,
			AngleDeg: 0,
		},
		Parameters: nil,
	},
	Calculation: Calculation{
		Iterations:   100,
		AntiAliasing: AA_NONE,
	},
	Palette: DefaultPalette,
}
View Source
var DefaultPalette = Palette{
	Params: palgen.Params{
		A: palgen.Vec3{0.5, 0.5, 0.5},
		B: palgen.Vec3{0.5, 0.5, 0.5},
		C: palgen.Vec3{1.0, 1.0, 1.0},
		D: palgen.Vec3{0.0, 0.0, 0.0},
	},
	SpaceColor: fcolor.RGB{R: 0, G: 0, B: 0},
	Period:     30,
	Shift:      0,
}
View Source
var DefaultPalette1 = Palette1{
	Colors: []fcolor.RGB{
		fcolor.RGB{R: 1, G: 1, B: 1},
		fcolor.RGB{R: 0, G: 0, B: 0},
	},
	SpaceColor: fcolor.RGB{R: 0, G: 0, B: 0},
	Period:     30,
}
View Source
var JuliaSetDefaultConst = Complex{
	Re: -0.74543,
	Im: 0.11301,
}
View Source
var PhoenixDefaultConst = Complex{
	Re: 0.56667,
	Im: -0.5,
}

Functions

func NewImageRGBA

func NewImageRGBA(size image.Point) *image.RGBA

func RenderImageRGBA

func RenderImageRGBA(m *image.RGBA, config Config,
	progress func(percent int))

func SaveImageJPEG

func SaveImageJPEG(filename string, m image.Image) error

func SaveImagePNG

func SaveImagePNG(filename string, m image.Image) error

func TraceOrbit

func TraceOrbit(t Orbit, n int) (int, bool)

Escape time algorithm

Types

type AntiAliasing

type AntiAliasing int
const (
	AA_NONE AntiAliasing = iota
	AA_4X                // 4 samples per pixel
	AA_9X                // 9 samples per pixel
	AA_16X               // 16 samples per pixel
	AA_25X               // 25 samples per pixel
)

func ParseAntiAliasing

func ParseAntiAliasing(s string) (AntiAliasing, error)

func (AntiAliasing) MarshalJSON

func (aa AntiAliasing) MarshalJSON() ([]byte, error)

func (AntiAliasing) String

func (aa AntiAliasing) String() string

func (*AntiAliasing) UnmarshalJSON

func (aa *AntiAliasing) UnmarshalJSON(data []byte) error

type Calculation

type Calculation struct {
	Iterations   int          `json:"iterations"`
	AntiAliasing AntiAliasing `json:"anti_aliasing"`
}

type Config

type Config struct {
	ImageSize   Size        `json:"image_size"`
	FractalInfo FractalInfo `json:"fractal_info"`
	Calculation Calculation `json:"calculation"`
	Palette     Palette     `json:"palette"`
}

func (*Config) MoveRelativeLocation

func (p *Config) MoveRelativeLocation(x, y float64)

relative value range: [-1 ... +1]

func (*Config) RotateDeg

func (p *Config) RotateDeg(angle int)

type FactoryBurningShip

type FactoryBurningShip struct{}

func (FactoryBurningShip) NewOrbit

func (FactoryBurningShip) NewOrbit(Z Complex) Orbit

type FactoryBurningShipIm

type FactoryBurningShipIm struct{}

func (FactoryBurningShipIm) NewOrbit

func (f FactoryBurningShipIm) NewOrbit(Z Complex) Orbit

type FactoryJuliaSet

type FactoryJuliaSet struct {
	C Complex
}

func (FactoryJuliaSet) NewOrbit

func (f FactoryJuliaSet) NewOrbit(Z Complex) Orbit

type FactoryMandelbrot

type FactoryMandelbrot struct{}

func (FactoryMandelbrot) NewOrbit

func (FactoryMandelbrot) NewOrbit(Z Complex) Orbit

type FactoryMandelbrotPow3

type FactoryMandelbrotPow3 struct{}

func (FactoryMandelbrotPow3) NewOrbit

func (FactoryMandelbrotPow3) NewOrbit(Z Complex) Orbit

type FactoryMandelbrotPow4

type FactoryMandelbrotPow4 struct{}

func (FactoryMandelbrotPow4) NewOrbit

func (FactoryMandelbrotPow4) NewOrbit(Z Complex) Orbit

type FactoryMandelbrotPow5

type FactoryMandelbrotPow5 struct{}

func (FactoryMandelbrotPow5) NewOrbit

func (FactoryMandelbrotPow5) NewOrbit(Z Complex) Orbit

type FactoryMandelbrotPow6

type FactoryMandelbrotPow6 struct{}

func (FactoryMandelbrotPow6) NewOrbit

func (FactoryMandelbrotPow6) NewOrbit(Z Complex) Orbit

type FactoryPhoenix

type FactoryPhoenix struct {
	C Complex
}

func (FactoryPhoenix) NewOrbit

func (f FactoryPhoenix) NewOrbit(Z Complex) Orbit

type FactorySpider

type FactorySpider struct{}

func (FactorySpider) NewOrbit

func (FactorySpider) NewOrbit(Z Complex) Orbit

type FactoryTricorn

type FactoryTricorn struct{}

func (FactoryTricorn) NewOrbit

func (f FactoryTricorn) NewOrbit(Z Complex) Orbit

type Formula

type Formula int
const (
	FormulaMandelbrot Formula = iota
	FormulaMandelbrotPow3
	FormulaMandelbrotPow4
	FormulaMandelbrotPow5
	FormulaMandelbrotPow6
	FormulaJuliaSet
	FormulaPhoenix
	FormulaBurningShip
	FormulaBurningShipIm
	FormulaSpider
	FormulaTricorn
)

func ParseFormula

func ParseFormula(s string) (Formula, error)

func (Formula) MarshalText

func (f Formula) MarshalText() (text []byte, err error)

func (Formula) String

func (f Formula) String() string

func (*Formula) UnmarshalText

func (f *Formula) UnmarshalText(text []byte) error

type FractalInfo

type FractalInfo struct {
	Formula    Formula   `json:"formula"`
	Location   Location  `json:"location"`
	Parameters []Complex `json:"parameters"`
}

type Location

type Location struct {
	Center   Complex `json:"center"`
	Radius   float64 `json:"radius"`
	AngleDeg int     `json:"angle_deg"`
}

type Orbit

type Orbit interface {
	Next() bool
}

type OrbitFactory

type OrbitFactory interface {
	NewOrbit(Complex) Orbit
}

type Palette

type Palette struct {
	Params     palgen.Params `json:"params"`
	SpaceColor fcolor.RGB    `json:"space_color"`
	Period     float64       `json:"period"`
	Shift      float64       `json:"shift"`
}

------------------------------------------------------------------------------

type Palette1

type Palette1 struct {
	Colors     []fcolor.RGB `json:"colors"`
	SpaceColor fcolor.RGB   `json:"space_color"`
	Period     float64      `json:"period"`
	Shift      float64      `json:"shift"`
}

type Size

type Size struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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