draw

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

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

Go to latest
Published: May 19, 2021 License: MIT Imports: 9 Imported by: 0

README

pixelop

A declarative graphics operation library built on top of Pixel2D and Tilepix, especially well suited for Approval Testing your app graphics!

Documentation

Overview

Example (ColorImageWinOp)
fmt.Println(Color(colornames.Red, Image(nil, "IMap")).String())
Output:

Color {255 0 0 255}:
  Image "IMap"
Example (ImdOpSequence)
circle := Circle(25, px.V(50, 100), 2)
smallCircle := Circle(3, px.V(1, 2), 4)
fmt.Println(ImdOpSequence(circle, smallCircle).String())
fmt.Println(ImdOpSequence(smallCircle, circle).String())
Output:

ImdOp Sequence:
  Circle radius 25 center Vec(50, 100) thickness 2
  Circle radius 3 center Vec(1, 2) thickness 4
ImdOp Sequence:
  Circle radius 3 center Vec(1, 2) thickness 4
  Circle radius 25 center Vec(50, 100) thickness 2
Example (LiftImdOp)
fmt.Println(ToWinOp(Circle(5, px.V(0, 4), 1)).String())
fmt.Println(ToWinOp(Line(px.V(0, 4), px.V(0, 4), 1)).String())
Output:

WinOp from ImdOp:
  Circle radius 5 center Vec(0, 4) thickness 1
WinOp from ImdOp:
  Line from Vec(0, 4) to Vec(0, 4) thickness 1
Example (MovedImageWinOp)
fmt.Println(Moved(px.V(55, -88), Image(nil, "IMap")).String())
Output:

Moved 55 pixels right 88 pixels down:
  Image "IMap"
Example (MovedLineWinOp)
fmt.Print(Moved(px.V(50, 100.41001), ToWinOp(Line(px.V(0, 4), px.V(5, 6), 10))).String())
Output:

Moved 50 pixels right 100 pixels up:
  WinOp from ImdOp:
    Line from Vec(0, 4) to Vec(5, 6) thickness 10
Example (MovedRectangleWinOp)
fmt.Println(Moved(px.V(-1, -2), ToWinOp(Rectangle(px.V(0, 4), px.V(5, 6), 10))).String())
Output:

Moved 1 pixels left 2 pixels down:
  WinOp from ImdOp:
    Rectangle from Vec(0, 4) to Vec(5, 6) thickness 10
Example (MovedTileLayerWinOp)
fmt.Println(Moved(px.V(100, -80), TileLayer(nil, "Foreground")).String())
Output:

Moved 100 pixels right 80 pixels down:
  TileLayer "Foreground"
Example (NestedSequence)
circle := Circle(25, px.V(50, 100), 2)
smallCircle := Circle(3, px.V(1, 2), 4)
fmt.Println(ImdOpSequence(ImdOpSequence(smallCircle, circle)).String())
Output:

ImdOp Sequence:
  ImdOp Sequence:
    Circle radius 3 center Vec(1, 2) thickness 4
    Circle radius 25 center Vec(50, 100) thickness 2
Example (SequencedWinOps)
mapImage := Color(colornames.Red, Image(nil, "IMap"))
ghostImage := Color(colornames.Yellow, Image(nil, "IGhost"))
sequence := OpSequence(mapImage, ghostImage)
fmt.Println(sequence.String())
Output:

WinOp Sequence:
  Color {255 0 0 255}:
    Image "IMap"
  Color {255 255 0 255}:
    Image "IGhost"
Example (ThenSequence)
sequence := ImdOpSequence().
	Then(Circle(25, px.V(50, 100), 2)).
	Then(Circle(3, px.V(1, 2), 4))
fmt.Println(sequence.String())
Output:

ImdOp Sequence:
  Circle radius 25 center Vec(50, 100) thickness 2
  Circle radius 3 center Vec(1, 2) thickness 4

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorOp

type ColorOp struct {
	// contains filtered or unexported fields
}

func (ColorOp) DrawTo

func (colorOp ColorOp) DrawTo(canvas *pixelgl.Canvas, context Context)

func (ColorOp) Lines

func (colorOp ColorOp) Lines() []string

func (ColorOp) Render

func (colorOp ColorOp) Render(mx px.Matrix, canvas *pixelgl.Canvas)

func (ColorOp) String

func (colorOp ColorOp) String() string

type Context

type Context struct {
	Transform px.Matrix
}

type ImageOp

type ImageOp struct {
	// contains filtered or unexported fields
}

func (ImageOp) DrawTo

func (imageOp ImageOp) DrawTo(canvas *pixelgl.Canvas, _ Context)

func (ImageOp) Lines

func (imageOp ImageOp) Lines() []string

func (ImageOp) Render

func (imageOp ImageOp) Render(_ px.Matrix, canvas *pixelgl.Canvas)

func (ImageOp) String

func (imageOp ImageOp) String() string

type ImdCircle

type ImdCircle struct {
	// contains filtered or unexported fields
}

func (ImdCircle) Lines

func (circle ImdCircle) Lines() []string

func (ImdCircle) Render

func (circle ImdCircle) Render(imd *imdraw.IMDraw)

func (ImdCircle) String

func (circle ImdCircle) String() string

type ImdColor

type ImdColor struct {
	Operation ImdOp
	// contains filtered or unexported fields
}

func (ImdColor) Lines

func (color ImdColor) Lines() []string

func (ImdColor) Render

func (color ImdColor) Render(imd *imdraw.IMDraw)

func (ImdColor) String

func (color ImdColor) String() string

type ImdLine

type ImdLine struct {
	// contains filtered or unexported fields
}

func (ImdLine) Lines

func (line ImdLine) Lines() []string

func (ImdLine) Render

func (line ImdLine) Render(imd *imdraw.IMDraw)

func (ImdLine) String

func (line ImdLine) String() string

type ImdOp

type ImdOp interface {
	String() string
	Lines() []string
	Render(imd *imdraw.IMDraw)
}

func Circle

func Circle(radius int, center pixel.Vec, thickness int) ImdOp
Example
circle := Circle(25, px.V(50, 100), 2)
smallCircle := Circle(3, px.V(1, 2), 4)
fmt.Println(circle.String())
fmt.Println(smallCircle.String())
Output:

Circle radius 25 center Vec(50, 100) thickness 2
Circle radius 3 center Vec(1, 2) thickness 4

func Colored

func Colored(color color.Color, imdOp ImdOp) ImdOp

func Line

func Line(from pixel.Vec, to pixel.Vec, thickness int) ImdOp
Example
line := Line(px.V(50, 100), px.V(101, 202), 2)
fmt.Println(line.String())
fmt.Println(Line(px.V(1, 2), px.V(3, 4), 5).String())
Output:

Line from Vec(50, 100) to Vec(101, 202) thickness 2
Line from Vec(1, 2) to Vec(3, 4) thickness 5

func Rectangle

func Rectangle(from pixel.Vec, to pixel.Vec, thickness int) ImdOp
Example
rectangle := Rectangle(px.V(50, 100), px.V(101, 202), 0)
fmt.Println(rectangle.String())
fmt.Println(Rectangle(px.V(1, 2), px.V(3, 4), 5).String())
Output:

Rectangle from Vec(50, 100) to Vec(101, 202) (filled)
Rectangle from Vec(1, 2) to Vec(3, 4) thickness 5

type ImdRectangle

type ImdRectangle struct {
	// contains filtered or unexported fields
}

func (ImdRectangle) Lines

func (rectangle ImdRectangle) Lines() []string

func (ImdRectangle) Render

func (rectangle ImdRectangle) Render(imd *imdraw.IMDraw)

func (ImdRectangle) String

func (rectangle ImdRectangle) String() string

type ImdSequence

type ImdSequence struct {
	// contains filtered or unexported fields
}

func ImdOpSequence

func ImdOpSequence(imdOps ...ImdOp) ImdSequence

func (ImdSequence) Lines

func (sequence ImdSequence) Lines() []string

func (ImdSequence) Render

func (sequence ImdSequence) Render(imd *imdraw.IMDraw)

func (ImdSequence) String

func (sequence ImdSequence) String() string

func (ImdSequence) Then

func (sequence ImdSequence) Then(imdOp ImdOp) ImdSequence

type OpMirrored

type OpMirrored struct {
	// contains filtered or unexported fields
}

func (OpMirrored) DrawTo

func (mirrored OpMirrored) DrawTo(canvas *pixelgl.Canvas, context Context)

func (OpMirrored) Lines

func (mirrored OpMirrored) Lines() []string

func (OpMirrored) Render

func (mirrored OpMirrored) Render(mx px.Matrix, canvas *pixelgl.Canvas)

func (OpMirrored) String

func (mirrored OpMirrored) String() string

type Paragraph

type Paragraph struct {
	// contains filtered or unexported fields
}

func Text

func Text(lines ...string) Paragraph
Example
fmt.Println(Text("First line", "Second line"))
Output:

Text:
  First line
  Second line

func (Paragraph) Lines

func (text Paragraph) Lines() []string

func (Paragraph) Render

func (text Paragraph) Render(tb *text.Text)

func (Paragraph) String

func (text Paragraph) String() string

type TextOp

type TextOp interface {
	String() string
	Lines() []string
	Render(tb *text.Text)
}

type TileLayerOp

type TileLayerOp struct {
	// contains filtered or unexported fields
}

func (TileLayerOp) DrawTo

func (tileLayerOp TileLayerOp) DrawTo(canvas *pixelgl.Canvas, _ Context)

func (TileLayerOp) Lines

func (tileLayerOp TileLayerOp) Lines() []string

func (TileLayerOp) Render

func (tileLayerOp TileLayerOp) Render(_ px.Matrix, canvas *pixelgl.Canvas)

func (TileLayerOp) String

func (tileLayerOp TileLayerOp) String() string

type WinImdOp

type WinImdOp struct {
	// contains filtered or unexported fields
}

func (WinImdOp) DrawTo

func (winImdOp WinImdOp) DrawTo(canvas *pixelgl.Canvas, _ Context)

func (WinImdOp) Lines

func (winImdOp WinImdOp) Lines() []string

func (WinImdOp) Render

func (winImdOp WinImdOp) Render(_ px.Matrix, canvas *pixelgl.Canvas)

func (WinImdOp) String

func (winImdOp WinImdOp) String() string

type WinMoved

type WinMoved struct {
	// contains filtered or unexported fields
}

func (WinMoved) DrawTo

func (winMoved WinMoved) DrawTo(canvas *pixelgl.Canvas, context Context)

func (WinMoved) Lines

func (winMoved WinMoved) Lines() []string

func (WinMoved) Render

func (winMoved WinMoved) Render(mx px.Matrix, canvas *pixelgl.Canvas)

func (WinMoved) String

func (winMoved WinMoved) String() string

type WinOp

type WinOp interface {
	String() string
	Lines() []string
	// Render TODO: should take a Context with matrix and color
	Render(mx pixel.Matrix, canvas *pixelgl.Canvas)
	DrawTo(canvas *pixelgl.Canvas, context Context)
}

func Color

func Color(color color.RGBA, winOp WinOp) WinOp
Example
circle := Circle(25, px.V(50, 100), 2)
smallCircle := Circle(3, px.V(1, 2), 4)
green := color.RGBA{R: 0, G: 1, B: 0}
fmt.Println(Colored(green, circle))
white := color.RGBA{R: 1, G: 1, B: 1}
fmt.Println(Colored(white, smallCircle))
Output:

Color {0 1 0 0}:
  Circle radius 25 center Vec(50, 100) thickness 2
Color {1 1 1 0}:
  Circle radius 3 center Vec(1, 2) thickness 4

func Image

func Image(image *px.Sprite, name string) WinOp

func Mirrored

func Mirrored(winOp WinOp) WinOp
Example
mapImage := Image(nil, "IMap")
ghostImage := Color(colornames.Yellow, Image(nil, "IGhost"))
seq := OpSequence(mapImage, ghostImage)
mirrored := Mirrored(seq)
fmt.Println(mirrored.String())
Output:

Mirrored around Y axis:
  WinOp Sequence:
    Image "IMap"
    Color {255 255 0 255}:
      Image "IGhost"

func Moved

func Moved(translation px.Vec, winOp WinOp) WinOp

func OpSequence

func OpSequence(ops ...WinOp) WinOp

func TileLayer

func TileLayer(tileMap *tilepix.Map, layerName string) WinOp

func ToWinOp

func ToWinOp(imdOp ImdOp) WinOp

type WinOpSequence

type WinOpSequence struct {
	// contains filtered or unexported fields
}

func (WinOpSequence) DrawTo

func (sequence WinOpSequence) DrawTo(canvas *pixelgl.Canvas, context Context)

func (WinOpSequence) Lines

func (sequence WinOpSequence) Lines() []string

func (WinOpSequence) Render

func (sequence WinOpSequence) Render(mx px.Matrix, canvas *pixelgl.Canvas)

func (WinOpSequence) String

func (sequence WinOpSequence) String() string

Jump to

Keyboard shortcuts

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