primitive

package
v0.0.0-...-ee5715b Latest Latest
Warning

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

Go to latest
Published: Sep 23, 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
	// contains filtered or unexported fields
}

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()

func (*Ellipse) Rasterize

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

func (*Ellipse) SVG

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

type Mode

type Mode int
const (
	ModeAny Mode = iota
	ModeTriangle
	ModeRectangle
	ModeEllipse
	ModeCircle
	ModeRotatedRectangle
)

type Model

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

func NewModel

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

func (*Model) Add

func (model *Model) Add(shape Shape)

func (*Model) BestHillClimbState

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

func (*Model) BestRandomState

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

func (*Model) Energy

func (model *Model) Energy(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 Mode, rnd *rand.Rand) *State

func (*Model) SVG

func (model *Model) SVG() string

func (*Model) Step

func (model *Model) Step()

type Rectangle

type Rectangle struct {
	W, H   int
	X1, Y1 int
	X2, Y2 int
	// contains filtered or unexported fields
}

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()

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
	// contains filtered or unexported fields
}

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()

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()
	Draw(dc *gg.Context)
	SVG(attrs string) string
}

type State

type State struct {
	Model  *Model
	Buffer *image.RGBA
	Shape  Shape
	Score  float64
}

func NewState

func NewState(model *Model, buffer *image.RGBA, shape Shape) *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
	// contains filtered or unexported fields
}

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()

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