primitive

package
v0.0.0-...-8c0f950 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2016 License: MIT Imports: 18 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 Copy

func Copy(dst, src *image.RGBA, lines []Scanline)

func Draw

func Draw(im *image.RGBA, c Color, lines []Scanline)

func LoadImage

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

func Log

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

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 {
	W, H   int
	X, Y   int
	Rx, Ry int
	Circle bool
}

func NewRandomCircle

func NewRandomCircle(w, h int, rnd *rand.Rand) *Ellipse

func NewRandomEllipse

func NewRandomEllipse(w, h int, rnd *rand.Rand) *Ellipse

func (*Ellipse) Copy

func (c *Ellipse) Copy() Shape

func (*Ellipse) Draw

func (c *Ellipse) Draw(dc *gg.Context)

func (*Ellipse) Mutate

func (c *Ellipse) Mutate(rnd *rand.Rand)

func (*Ellipse) Rasterize

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

func (*Ellipse) SVG

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

type Model

type Model struct {
	W, H       int
	Background Color
	Target     *image.RGBA
	Current    *image.RGBA
	Buffer     *image.RGBA
	Context    *gg.Context
	Score      float64
	Size       int
	Shapes     []Shape
	Colors     []Color
	Scores     []float64
}

func NewModel

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

func (*Model) Add

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

func (*Model) BestHillClimbState

func (model *Model) BestHillClimbState(buffer *image.RGBA, t ShapeType, a, n, age, m int, rnd *rand.Rand) *State

func (*Model) BestRandomState

func (model *Model) BestRandomState(buffer *image.RGBA, t ShapeType, a, n int, rnd *rand.Rand) *State

func (*Model) Energy

func (model *Model) Energy(alpha int, shape Shape, buffer *image.RGBA) float64

func (*Model) Frames

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

func (*Model) RandomState

func (model *Model) RandomState(buffer *image.RGBA, t ShapeType, a int, rnd *rand.Rand) *State

func (*Model) SVG

func (model *Model) SVG() string

func (*Model) Step

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

type Rectangle

type Rectangle struct {
	W, H   int
	X1, Y1 int
	X2, Y2 int
}

func NewRandomRectangle

func NewRandomRectangle(w, h int, rnd *rand.Rand) *Rectangle

func (*Rectangle) Copy

func (r *Rectangle) Copy() Shape

func (*Rectangle) Draw

func (r *Rectangle) Draw(dc *gg.Context)

func (*Rectangle) Mutate

func (r *Rectangle) Mutate(rnd *rand.Rand)

func (*Rectangle) Rasterize

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

func (*Rectangle) SVG

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

type RotatedRectangle

type RotatedRectangle struct {
	W, H   int
	X, Y   int
	Sx, Sy int
	Angle  int
}

func NewRandomRotatedRectangle

func NewRandomRotatedRectangle(w, h int, rnd *rand.Rand) *RotatedRectangle

func (*RotatedRectangle) Copy

func (r *RotatedRectangle) Copy() Shape

func (*RotatedRectangle) Draw

func (r *RotatedRectangle) Draw(dc *gg.Context)

func (*RotatedRectangle) Mutate

func (r *RotatedRectangle) Mutate(rnd *rand.Rand)

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
}

type Shape

type Shape interface {
	Rasterize() []Scanline
	Copy() Shape
	Mutate(rnd *rand.Rand)
	Draw(dc *gg.Context)
	SVG(attrs string) string
}

type ShapeType

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

type State

type State struct {
	Model       *Model
	Buffer      *image.RGBA
	Alpha       int
	Shape       Shape
	MutateAlpha bool
	// contains filtered or unexported fields
}

func NewState

func NewState(model *Model, buffer *image.RGBA, alpha int, shape Shape, rnd *rand.Rand) *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 {
	W, H   int
	X1, Y1 int
	X2, Y2 int
	X3, Y3 int
}

func NewRandomTriangle

func NewRandomTriangle(w, h int, rnd *rand.Rand) *Triangle

func (*Triangle) Copy

func (t *Triangle) Copy() Shape

func (*Triangle) Draw

func (t *Triangle) Draw(dc *gg.Context)

func (*Triangle) Mutate

func (t *Triangle) Mutate(rnd *rand.Rand)

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

Jump to

Keyboard shortcuts

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