shapes

package
v0.0.0-...-5daf3a2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: MIT, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawShapes

func DrawShapes(img draw.Image, x, y int, shapes ...Shaper) error

func FilledImage

func FilledImage(width, height int, fill color.Color) draw.Image

func SaveImage

func SaveImage(img image.Image, filename string) error

Types

type Circle

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

The zero value is invalid! Use NewCircle() to create a valid Circle.

func NewCircle

func NewCircle(fill color.Color, radius int) *Circle

By calling newShape() we pass on any checking to newShape() without having to know what if any is required.

func (*Circle) Draw

func (circle *Circle) Draw(img draw.Image, x, y int) error

func (Circle) Fill

func (shape Circle) Fill() color.Color

func (*Circle) Radius

func (circle *Circle) Radius() int

func (*Circle) SetFill

func (shape *Circle) SetFill(fill color.Color)

func (*Circle) SetRadius

func (circle *Circle) SetRadius(radius int)

func (*Circle) String

func (circle *Circle) String() string

type CircularShaper

type CircularShaper interface {
	Shaper // Fill(); SetFill(); Draw()
	Radius() int
	SetRadius(radius int)
}

type Option

type Option struct {
	Fill   color.Color
	Radius int
}

type RegularPolygon

type RegularPolygon struct {
	*Circle
	// contains filtered or unexported fields
}

The zero value is invalid! Use NewRegularPolygon() to create a valid RegularPolygon.

func NewRegularPolygon

func NewRegularPolygon(fill color.Color, radius,
	sides int) *RegularPolygon

func (*RegularPolygon) Draw

func (polygon *RegularPolygon) Draw(img draw.Image, x, y int) error

func (RegularPolygon) Fill

func (shape RegularPolygon) Fill() color.Color

func (RegularPolygon) SetFill

func (shape RegularPolygon) SetFill(fill color.Color)

func (*RegularPolygon) SetSides

func (polygon *RegularPolygon) SetSides(sides int)

func (*RegularPolygon) Sides

func (polygon *RegularPolygon) Sides() int

func (*RegularPolygon) String

func (polygon *RegularPolygon) String() string

type RegularPolygonalShaper

type RegularPolygonalShaper interface {
	CircularShaper // Fill(); SetFill(); Draw(); Radius(); SetRadius()
	Sides() int
	SetSides(sides int)
}

type Shaper

type Shaper interface {
	Fill() color.Color
	SetFill(fill color.Color)
	Draw(img draw.Image, x, y int) error
}

func New

func New(shape string, option Option) (Shaper, error)

Factory function: The returned Shaper can only call Shaper methods unless we use type assertion: see main() in ../main.go for examples. Note that this function could return a CircularShaper (in which case no type assertion would be needed to set the Radius); but we prefer the to be more general since that allows us to add other non-CircularShaper shapes later without requiring existing callers to be changed.

Jump to

Keyboard shortcuts

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