package vector

Import Path
	golang.org/x/image/vector (on go.dev)

Dependency Relation
	imports 4 packages, and imported by one package

Involved Source Files acc_amd64.go raster_fixed.go raster_floating.go Package vector provides a rasterizer for 2-D vector graphics. acc_amd64.s
Code Examples package main import ( "image" "image/draw" "os" "golang.org/x/image/vector" ) func main() { const ( width = 30 height = 20 ) // Define a closed shape with three edges: two linear and one quadratic. // One of its vertices is at the top-left corner of the (1, 2) pixel, which // is also the bottom-right corner of the (0, 1) pixel. // // Co-ordinates can be floating point numbers, not just integers. They can // also be outside the vector.Rasterizer's dimensions. The shapes will be // clipped during rasterization. r := vector.NewRasterizer(width, height) r.DrawOp = draw.Src r.MoveTo(1, 2) r.LineTo(20, 2) r.QuadTo(40.5, 15, 10, 20) r.ClosePath() // Finish the rasterization: the conversion from vector graphics (shapes) // to raster graphics (pixels). Co-ordinates are now integers. dst := image.NewAlpha(image.Rect(0, 0, width, height)) r.Draw(dst, dst.Bounds(), image.Opaque, image.Point{}) // Visualize the pixels. const asciiArt = ".++8" buf := make([]byte, 0, height*(width+1)) for y := 0; y < height; y++ { for x := 0; x < width; x++ { a := dst.AlphaAt(x, y).A buf = append(buf, asciiArt[a>>6]) } buf = append(buf, '\n') } os.Stdout.Write(buf) }
Package-Level Type Names (only one)
/* sort by: | */
Raster is a 2-D vector graphics rasterizer. The zero value is usable, in that it is a Rasterizer whose rendered mask image has zero width and zero height. Call Reset to change its bounds. DrawOp is the operator used for the Draw method. The zero value is draw.Over. Bounds returns the rectangle from (0, 0) to the width and height passed to NewRasterizer or Reset. ClosePath closes the current path. CubeTo adds a cubic Bézier segment, from the pen via (bx, by) and (cx, cy) to (dx, dy), and moves the pen to (dx, dy). The coordinates are allowed to be out of the Rasterizer's bounds. Draw implements the Drawer interface from the standard library's image/draw package. The vector paths previously added via the XxxTo calls become the mask for drawing src onto dst. LineTo adds a line segment, from the pen to (bx, by), and moves the pen to (bx, by). The coordinates are allowed to be out of the Rasterizer's bounds. MoveTo starts a new path and moves the pen to (ax, ay). The coordinates are allowed to be out of the Rasterizer's bounds. Pen returns the location of the path-drawing pen: the last argument to the most recent XxxTo call. QuadTo adds a quadratic Bézier segment, from the pen via (bx, by) to (cx, cy), and moves the pen to (cx, cy). The coordinates are allowed to be out of the Rasterizer's bounds. Reset resets a Rasterizer as if it was just returned by NewRasterizer. This includes setting z.DrawOp to draw.Over. Size returns the width and height passed to NewRasterizer or Reset. *Rasterizer : image/draw.Drawer func NewRasterizer(w, h int) *Rasterizer
Package-Level Functions (only one)
NewRasterizer returns a new Rasterizer whose rendered mask image is bounded by the given width and height.