primitive

package
v0.0.0-...-7aa77e1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogLevel int

Functions

func AverageImageColor

func AverageImageColor(im image.Image) color.NRGBA

func LoadImage

func LoadImage(path string) (image.Image, error)

func Log

func Log(level int, format string, a ...interface{})

func NumberString

func NumberString(x float64) string

func PreAnneal

func PreAnneal(state Annealable, iterations int) float64

func SaveFile

func SaveFile(path, contents string) error

func SaveGIF

func SaveGIF(path string, frames []image.Image, delay, lastDelay int) error

func SaveGIFImageMagick

func SaveGIFImageMagick(path string, frames []image.Image, delay, lastDelay int) error

func SaveJPG

func SaveJPG(path string, im image.Image, quality int) error

func SavePNG

func SavePNG(path string, im image.Image) error

Types

type Annealable

type Annealable interface {
	Energy() float64
	DoMove() interface{}
	UndoMove(interface{})
	Copy() Annealable
}

func Anneal

func Anneal(state Annealable, maxTemp, minTemp float64, steps int) Annealable

func HillClimb

func HillClimb(state Annealable, maxAge int) Annealable

type Color

type Color struct {
	R, G, B, A int
}

func MakeColor

func MakeColor(c color.Color) Color

func MakeHexColor

func MakeHexColor(x string) Color

func (*Color) NRGBA

func (c *Color) NRGBA() color.NRGBA

type Ellipse

type Ellipse struct {
	Worker *Worker
	X, Y   int
	Rx, Ry int
	Circle bool
}

func NewRandomCircle

func NewRandomCircle(worker *Worker) *Ellipse

func (*Ellipse) BORST

func (c *Ellipse) BORST(attrs string) string

* Is actually a circle >.> not an ellipse

func (*Ellipse) Copy

func (c *Ellipse) Copy() Shape

func (*Ellipse) Draw

func (c *Ellipse) Draw(dc *gg.Context, scale float64)

func (*Ellipse) Mutate

func (c *Ellipse) Mutate()

func (*Ellipse) Rasterize

func (c *Ellipse) Rasterize() []Scanline

func (*Ellipse) SVG

func (c *Ellipse) SVG(attrs string) string

type Heatmap

type Heatmap struct {
	W, H  int
	Count []uint64
}

func NewHeatmap

func NewHeatmap(w, h int) *Heatmap

func (*Heatmap) Add

func (h *Heatmap) Add(lines []Scanline)

func (*Heatmap) AddHeatmap

func (h *Heatmap) AddHeatmap(a *Heatmap)

func (*Heatmap) Clear

func (h *Heatmap) Clear()

func (*Heatmap) Image

func (h *Heatmap) Image(gamma float64) *image.Gray16

type Model

type Model struct {
	Sw, Sh     int
	Scale      float64
	Background Color
	Target     *image.RGBA
	Current    *image.RGBA
	Context    *gg.Context
	Score      float64
	Shapes     []Shape
	Colors     []Color
	Scores     []float64
	Workers    []*Worker
}

func NewModel

func NewModel(target image.Image, background Color, size, numWorkers int) *Model

func (*Model) Add

func (model *Model) Add(shape Shape, alpha int)

func (*Model) BOSRT

func (model *Model) BOSRT() string

func (*Model) Frames

func (model *Model) Frames(scoreDelta float64) []image.Image

func (*Model) SVG

func (model *Model) SVG() string

func (*Model) Step

func (model *Model) Step(shapeType ShapeType, alpha, repeat int) int

type Rectangle

type Rectangle struct {
	Worker *Worker
	X1, Y1 int
	X2, Y2 int
}

func NewRandomRectangle

func NewRandomRectangle(worker *Worker) *Rectangle

func (*Rectangle) BORST

func (r *Rectangle) BORST(attrs string) string

func (*Rectangle) Copy

func (r *Rectangle) Copy() Shape

func (*Rectangle) Draw

func (r *Rectangle) Draw(dc *gg.Context, scale float64)

func (*Rectangle) Mutate

func (r *Rectangle) Mutate()

func (*Rectangle) Rasterize

func (r *Rectangle) Rasterize() []Scanline

func (*Rectangle) SVG

func (r *Rectangle) SVG(attrs string) string

type Scanline

type Scanline struct {
	Y, X1, X2 int
	Alpha     uint32
}

type Shape

type Shape interface {
	Rasterize() []Scanline
	Copy() Shape
	Mutate()
	Draw(dc *gg.Context, scale float64)
	SVG(attrs string) string
	BORST(attrs string) string
}

type ShapeType

type ShapeType int
const (
	ShapeTypeAny ShapeType = iota
	//ShapeTypeTriangle
	ShapeTypeRectangle
	//ShapeTypeEllipse
	ShapeTypeCircle
)

type State

type State struct {
	Worker      *Worker
	Shape       Shape
	Alpha       int
	MutateAlpha bool
	Score       float64
}

func NewState

func NewState(worker *Worker, shape Shape, alpha int) *State

func (*State) Copy

func (state *State) Copy() Annealable

func (*State) DoMove

func (state *State) DoMove() interface{}

func (*State) Energy

func (state *State) Energy() float64

func (*State) UndoMove

func (state *State) UndoMove(undo interface{})

type Worker

type Worker struct {
	W, H       int
	Target     *image.RGBA
	Current    *image.RGBA
	Buffer     *image.RGBA
	Rasterizer *raster.Rasterizer
	Lines      []Scanline
	Heatmap    *Heatmap
	Rnd        *rand.Rand
	Score      float64
	Counter    int
}

func NewWorker

func NewWorker(target *image.RGBA) *Worker

func (*Worker) BestHillClimbState

func (worker *Worker) BestHillClimbState(t ShapeType, a, n, age, m int) *State

func (*Worker) BestRandomState

func (worker *Worker) BestRandomState(t ShapeType, a, n int) *State

func (*Worker) Energy

func (worker *Worker) Energy(shape Shape, alpha int) float64

func (*Worker) Init

func (worker *Worker) Init(current *image.RGBA, score float64)

func (*Worker) RandomState

func (worker *Worker) RandomState(t ShapeType, a int) *State

Jump to

Keyboard shortcuts

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