gfx

package
v0.0.0-...-ae32867 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package gfx implements a backend for graphics. The backend connects to various drawing engines (e.g., raster, SVG, PDF, ...).

We abstract the details away with an interface Canvas, which represents a rectangular drawing area. The main operation on a Canvas is AddContour, the drawing or filling of a path.

Clients often won't use Canvas directly, but rather an enclosing struct type Picture, which holds a Canvas plus some administrative information.

BSD License

Copyright (c) 2017-21, Norbert Pillmayer <norbert@pillmayer.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of Norbert Pillmayer nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const PENCIRCLE int = 1

PENCIRCLE is a pen with a round nib

View Source
const PENSQUARE int = 2

PENSQUARE is a pen with a square nib

Variables

This section is empty.

Functions

func G

func G() tracing.Trace

G traces to the graphics tracer.

Types

type Canvas

type Canvas interface {
	W() float64                                                    // width
	H() float64                                                    // height
	AddContour(DrawableContour, float64, color.Color, color.Color) // filldraw with pen with colors
	SetOption(int)                                                 // set a drawing option
}

Canvas is an interface type for a drawing canvas.

type DrawableContour

type DrawableContour interface {
	IsCycle() bool
	Start() arithm.Pair
	ToNextKnot() (k arithm.Pair, c1 arithm.Pair, c2 arithm.Pair)
}

DrawableContour is an interface for a stroke. The central operation on Canvases is AddContour, the drawing and/or filling of a path. Different clients may have a different understanding of what a path is and how to store it. Interface DrawableContour tries to be a common denomiator for drawing operations on paths.

The 3 parameters for ToNextKnot() are the target point, together with 2 optional control points for spline curves (quadratic or cubic).

func NewDrawablePath

func NewDrawablePath(path path.HobbyPath, controls path.SplineControls) DrawableContour

NewDrawablePath creates an immutable adapter to contours from cubic splines.

func NewDrawablePolygon

func NewDrawablePolygon(pg polygon.Polygon) DrawableContour

NewDrawablePolygon creates an immutable bridge to contours from polygons.

type OutputRoutine

type OutputRoutine interface {
	Shipout(pic *Picture, gfxFormat string) bool
}

OutputRoutine is an interface for output routines to ship out completed images.

type Pen

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

Pen is a drawing pen.

func NewPencircle

func NewPencircle(diam float64) *Pen

NewPencircle creates a new round pen.

func NewPensquare

func NewPensquare(diam float64) *Pen

NewPensquare create a new square pen.

type Picture

type Picture struct {
	Name string
	// contains filtered or unexported fields
}

Picture is the type for the backend to work with.

func NewPicture

func NewPicture(name string, canvas Canvas) *Picture

NewPicture creates a new Picture. Caller has to provide an identifier, a width, a height and a Canvas.

func (*Picture) Draw

func (pic *Picture) Draw(contour DrawableContour)

Draw a line. Uses the current pen.

func (*Picture) Fill

func (pic *Picture) Fill(contour DrawableContour)

Fill a closed path. Uses the current pen.

func (*Picture) FillDraw

func (pic *Picture) FillDraw(contour DrawableContour)

FillDraw is MetaPost's filldraw command. Uses the current pen and color.

func (*Picture) SetColor

func (pic *Picture) SetColor(color color.Color)

SetColor sets the current color. Will be used for subsequent drawing operations.

func (*Picture) SetPen

func (pic *Picture) SetPen(pen *Pen)

SetPen sets the current pen. Will be used for subsequent drawing operations.

Directories

Path Synopsis
Package pngcanvas implements a canvas type as an adapter to the Go-Graphics drawing library.
Package pngcanvas implements a canvas type as an adapter to the Go-Graphics drawing library.
Package svg implements operations on/for SVG graphics.
Package svg implements operations on/for SVG graphics.
Package vectorcanvas implements a vanilla canvas type for vector drawings.
Package vectorcanvas implements a vanilla canvas type for vector drawings.

Jump to

Keyboard shortcuts

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