`import "github.com/faiface/pixel/imdraw"`

Package imdraw implements a basic primitive geometry shape and pictured polygon drawing for Pixel with a nice immediate-mode-like API.

- type EndShape
- type IMDraw
- func New(pic pixel.Picture) *IMDraw
- func (imd *IMDraw) Circle(radius, thickness float64)
- func (imd *IMDraw) CircleArc(radius, low, high, thickness float64)
- func (imd *IMDraw) Clear()
- func (imd *IMDraw) Draw(t pixel.Target)
- func (imd *IMDraw) Ellipse(radius pixel.Vec, thickness float64)
- func (imd *IMDraw) EllipseArc(radius pixel.Vec, low, high, thickness float64)
- func (imd *IMDraw) Line(thickness float64)
- func (imd *IMDraw) MakePicture(p pixel.Picture) pixel.TargetPicture
- func (imd *IMDraw) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles
- func (imd *IMDraw) Polygon(thickness float64)
- func (imd *IMDraw) Push(pts ...pixel.Vec)
- func (imd *IMDraw) Rectangle(thickness float64)
- func (imd *IMDraw) Reset()
- func (imd *IMDraw) SetColorMask(color color.Color)
- func (imd *IMDraw) SetMatrix(m pixel.Matrix)

EndShape specifies the shape of an end of a line or a curve.

❖

const ( // NoEndShape leaves a line point with no special end shape. NoEndShape EndShape = iota // SharpEndShape is a sharp triangular end shape. SharpEndShape // RoundEndShape is a circular end shape. RoundEndShape )

❖

type IMDraw struct { Color color.Color Picture pixel.Vec Intensity float64 Precision int EndShape EndShape // contains filtered or unexported fields }

IMDraw is an immediate-mode-like shape drawer and BasicTarget. IMDraw supports TrianglesPosition, TrianglesColor, TrianglesPicture and PictureColor.

IMDraw, other than a regular BasicTarget, is used to draw shapes. To draw shapes, you first need to Push some points to IMDraw:

imd := pixel.NewIMDraw(pic) // use nil pic if you only want to draw primitive shapes imd.Push(pixel.V(100, 100)) imd.Push(pixel.V(500, 100))

Once you have Pushed some points, you can use them to draw a shape, such as a line:

imd.Line(20) // draws a 20 units thick line

Set exported fields to change properties of Pushed points:

imd.Color = pixel.RGB(1, 0, 0) imd.Push(pixel.V(200, 200)) imd.Circle(400, 0)

Here is the list of all available point properties (need to be set before Pushing a point):

- Color - applies to all - Picture - coordinates, only applies to filled polygons - Intensity - picture intensity, only applies to filled polygons - Precision - curve drawing precision, only applies to circles and ellipses - EndShape - shape of the end of a line, only applies to lines and outlines

And here's the list of all shapes that can be drawn (all, except for line, can be filled or outlined):

- Line - Polygon - Circle - Circle arc - Ellipse - Ellipse arc

New creates a new empty IMDraw. An optional Picture can be used to draw with a Picture.

If you just want to draw primitive shapes, pass nil as the Picture.

Circle draws a circle of the specified radius around each Pushed point. If the thickness is 0, the circle will be filled, otherwise a circle outline of the specified thickness will be drawn.

CircleArc draws a circle arc of the specified radius around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.CircleArc(40, 0, 8*math.Pi, 0)

This line will fill the whole circle 4 times.

Clear removes all drawn shapes from the IM. This does not remove Pushed points.

Draw draws all currently drawn shapes inside the IM onto another Target.

Note, that IMDraw's matrix and color mask have no effect here.

Ellipse draws an ellipse of the specified radius in each axis around each Pushed points. If the thickness is 0, the ellipse will be filled, otherwise an ellipse outline of the specified thickness will be drawn.

EllipseArc draws an ellipse arc of the specified radius in each axis around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.EllipseArc(pixel.V(100, 50), 0, 8*math.Pi, 0)

This line will fill the whole ellipse 4 times.

Line draws a polyline of the specified thickness between the Pushed points.

MakePicture returns a specialized copy of the provided Picture that draws onto this IMDraw.

MakeTriangles returns a specialized copy of the provided Triangles that draws onto this IMDraw.

Polygon draws a polygon from the Pushed points. If the thickness is 0, the convex polygon will be filled. Otherwise, an outline of the specified thickness will be drawn. The outline does not have to be convex.

Note, that the filled polygon does not have to be strictly convex. The way it's drawn is that a triangle is drawn between each two adjacent points and the first Pushed point. You can use this property to draw certain kinds of concave polygons.

Push adds some points to the IM queue. All Pushed points will have the same properties except for the position.

Rectangle draws a rectangle between each two subsequent Pushed points. Drawing a rectangle between two points means drawing a rectangle with sides parallel to the axes of the coordinate system, where the two points specify it's two opposite corners.

If the thickness is 0, rectangles will be filled, otherwise will be outlined with the given thickness.

Reset restores all point properties to defaults and removes all Pushed points.

This does not affect matrix and color mask set by SetMatrix and SetColorMask.

SetColorMask sets a color that all further point's color will be multiplied by.

SetMatrix sets a Matrix that all further points will be transformed by.

Package imdraw imports 3 packages (graph) and is imported by 37 packages. Updated 2018-10-02. Refresh now. Tools for package owners.