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 ¶
const PENCIRCLE int = 1
PENCIRCLE is a pen with a round nib
const PENSQUARE int = 2
PENSQUARE is a pen with a square nib
Variables ¶
This section is empty.
Functions ¶
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 ¶
OutputRoutine is an interface for output routines to ship out completed images.
type Picture ¶
type Picture struct { Name string // contains filtered or unexported fields }
Picture is the type for the backend to work with.
func NewPicture ¶
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.
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. |