primitive

package
v0.0.0-...-0373c21 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 19 Imported by: 33

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 NewRandomEllipse

func NewRandomEllipse(worker *Worker) *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) 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 Polygon

type Polygon struct {
	Worker *Worker
	Order  int
	Convex bool
	X, Y   []float64
}

func NewRandomPolygon

func NewRandomPolygon(worker *Worker, order int, convex bool) *Polygon

func (*Polygon) Copy

func (p *Polygon) Copy() Shape

func (*Polygon) Draw

func (p *Polygon) Draw(dc *gg.Context, scale float64)

func (*Polygon) Mutate

func (p *Polygon) Mutate()

func (*Polygon) Rasterize

func (p *Polygon) Rasterize() []Scanline

func (*Polygon) SVG

func (p *Polygon) SVG(attrs string) string

func (*Polygon) Valid

func (p *Polygon) Valid() bool

type Quadratic

type Quadratic struct {
	Worker *Worker
	X1, Y1 float64
	X2, Y2 float64
	X3, Y3 float64
	Width  float64
}

func NewRandomQuadratic

func NewRandomQuadratic(worker *Worker) *Quadratic

func (*Quadratic) Copy

func (q *Quadratic) Copy() Shape

func (*Quadratic) Draw

func (q *Quadratic) Draw(dc *gg.Context, scale float64)

func (*Quadratic) Mutate

func (q *Quadratic) Mutate()

func (*Quadratic) Rasterize

func (q *Quadratic) Rasterize() []Scanline

func (*Quadratic) SVG

func (q *Quadratic) SVG(attrs string) string

func (*Quadratic) Valid

func (q *Quadratic) Valid() bool

type Rectangle

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

func NewRandomRectangle

func NewRandomRectangle(worker *Worker) *Rectangle

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 RotatedEllipse

type RotatedEllipse struct {
	Worker *Worker
	X, Y   float64
	Rx, Ry float64
	Angle  float64
}

func NewRandomRotatedEllipse

func NewRandomRotatedEllipse(worker *Worker) *RotatedEllipse

func (*RotatedEllipse) Copy

func (c *RotatedEllipse) Copy() Shape

func (*RotatedEllipse) Draw

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

func (*RotatedEllipse) Mutate

func (c *RotatedEllipse) Mutate()

func (*RotatedEllipse) Rasterize

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

func (*RotatedEllipse) SVG

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

type RotatedRectangle

type RotatedRectangle struct {
	Worker *Worker
	X, Y   int
	Sx, Sy int
	Angle  int
}

func NewRandomRotatedRectangle

func NewRandomRotatedRectangle(worker *Worker) *RotatedRectangle

func (*RotatedRectangle) Copy

func (r *RotatedRectangle) Copy() Shape

func (*RotatedRectangle) Draw

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

func (*RotatedRectangle) Mutate

func (r *RotatedRectangle) Mutate()

func (*RotatedRectangle) Rasterize

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

func (*RotatedRectangle) SVG

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

func (*RotatedRectangle) Valid

func (r *RotatedRectangle) Valid() bool

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
}

type ShapeType

type ShapeType int
const (
	ShapeTypeAny ShapeType = iota
	ShapeTypeTriangle
	ShapeTypeRectangle
	ShapeTypeEllipse
	ShapeTypeCircle
	ShapeTypeRotatedRectangle
	ShapeTypeQuadratic
	ShapeTypeRotatedEllipse
	ShapeTypePolygon
)

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 Triangle

type Triangle struct {
	Worker *Worker
	X1, Y1 int
	X2, Y2 int
	X3, Y3 int
}

func NewRandomTriangle

func NewRandomTriangle(worker *Worker) *Triangle

func (*Triangle) Copy

func (t *Triangle) Copy() Shape

func (*Triangle) Draw

func (t *Triangle) Draw(dc *gg.Context, scale float64)

func (*Triangle) Mutate

func (t *Triangle) Mutate()

func (*Triangle) Rasterize

func (t *Triangle) Rasterize() []Scanline

func (*Triangle) SVG

func (t *Triangle) SVG(attrs string) string

func (*Triangle) Valid

func (t *Triangle) Valid() bool

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