drawer

package module
v0.0.0-...-06f2522 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2015 License: BSD-3-Clause Imports: 5 Imported by: 0

README

Drawer

Basic drawing functions for Go

This library was started after this conversation on the golang mailing list. While the go standard libray has support for image manipuation, it lacks functions to draw basic shapes and lines. The intent of this library is to provide those features, and provided there is enough support, merge them into the standard library.

How to use

Install this package in the normal way using go get. Examples for how to use this library can be found in the examples folder.

Document is found here.

Issues & Contributing

This library is not currently production ready but the goal is to become so. Please create an issue for any bugs or features requests. Well written bug reports will be fixed promptly while feature requests will take more time.

Documentation

Overview

This package contains several structs for drawing, all following a similar convention:

Structs have a constructor function that takes basic arguments for that type, ie:

func NewLineDrawer(draw.Image, image.Point, image.Point, color.Color)

All functions in the Drawer structs return a pointer to itself to allow chaining:

NewLineDrawer(src, start, end, color.RGBA{255, 0, 0, 255}).SetThickness(10).Draw()

This also allows you to reuse an instance:

lineDrawer := NewLineDrawer(draw.Image, image.Point, image.Point, color.Color).Draw()
lineDrawer = lineDrawer.SetStart(image.Pt(0, 50)).Draw()

This construct allows easy addition of new features without compromising reverse compatibilty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Blend

func Blend(img draw.Image, x int, y int, c color.Color)

Performs alpha blending on the pixel on img.At(x,y). While draw.Set(x,y) *sets* the color to c, Blend uses the existing background to create a new color that is a mix of the existing annew color. This is similar to treating the two colors as stained glass windows laying over eachother. Not that if the new color is completely opache, Blend() and Set() have the same result.

func ColorToRGBA

func ColorToRGBA(c color.Color) color.RGBA

A convineice function that creates a color.RGBA struct from color.Color interface. While fairly straitforward, tedious conversions need to be made to change between uint32 and uint8.

func Fill

func Fill(img draw.Image, color color.Color)

A convinience function that sets all of the pixels in img to color

Types

type LineDrawer

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

func NewLineDrawer

func NewLineDrawer(img draw.Image, start image.Point, end image.Point, color color.Color) *LineDrawer

func (*LineDrawer) Draw

func (this *LineDrawer) Draw() *LineDrawer

func (*LineDrawer) SetColor

func (this *LineDrawer) SetColor(c color.Color) *LineDrawer

func (*LineDrawer) SetEnd

func (this *LineDrawer) SetEnd(end image.Point) *LineDrawer

func (*LineDrawer) SetImage

func (this *LineDrawer) SetImage(img draw.Image) *LineDrawer

func (*LineDrawer) SetStart

func (this *LineDrawer) SetStart(start image.Point) *LineDrawer

func (*LineDrawer) SetThickness

func (this *LineDrawer) SetThickness(thick float64) *LineDrawer

type RectDrawer

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

func NewRectDrawer

func NewRectDrawer(img draw.Image, rect image.Rectangle, color color.Color) *RectDrawer

Draws rect in color onto img. rect must be well-formed (see Rectangle.Canon()).

func (*RectDrawer) Draw

func (this *RectDrawer) Draw() *RectDrawer

func (*RectDrawer) SetColor

func (this *RectDrawer) SetColor(color color.Color) *RectDrawer

func (*RectDrawer) SetFilled

func (this *RectDrawer) SetFilled(isFilled bool) *RectDrawer

func (*RectDrawer) SetImage

func (this *RectDrawer) SetImage(img draw.Image) *RectDrawer

func (*RectDrawer) SetRect

func (this *RectDrawer) SetRect(rect image.Rectangle) *RectDrawer

func (*RectDrawer) SetThickness

func (this *RectDrawer) SetThickness(thickness int) *RectDrawer

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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