pixel: github.com/faiface/pixel/imdraw Index | Files

package imdraw

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.

Index

Package Files

imdraw.go

type EndShape Uses

type EndShape int

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 Uses

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

func New Uses

func New(pic pixel.Picture) *IMDraw

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.

func (*IMDraw) Circle Uses

func (imd *IMDraw) Circle(radius, thickness float64)

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.

func (*IMDraw) CircleArc Uses

func (imd *IMDraw) CircleArc(radius, low, high, thickness float64)

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.

func (*IMDraw) Clear Uses

func (imd *IMDraw) Clear()

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

func (*IMDraw) Draw Uses

func (imd *IMDraw) Draw(t pixel.Target)

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

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

func (*IMDraw) Ellipse Uses

func (imd *IMDraw) Ellipse(radius pixel.Vec, thickness float64)

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.

func (*IMDraw) EllipseArc Uses

func (imd *IMDraw) EllipseArc(radius pixel.Vec, low, high, thickness float64)

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.

func (*IMDraw) Line Uses

func (imd *IMDraw) Line(thickness float64)

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

func (*IMDraw) MakePicture Uses

func (imd *IMDraw) MakePicture(p pixel.Picture) pixel.TargetPicture

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

func (*IMDraw) MakeTriangles Uses

func (imd *IMDraw) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles

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

func (*IMDraw) Polygon Uses

func (imd *IMDraw) Polygon(thickness float64)

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.

func (*IMDraw) Push Uses

func (imd *IMDraw) Push(pts ...pixel.Vec)

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

func (*IMDraw) Rectangle Uses

func (imd *IMDraw) Rectangle(thickness float64)

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.

func (*IMDraw) Reset Uses

func (imd *IMDraw) Reset()

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.

func (*IMDraw) SetColorMask Uses

func (imd *IMDraw) SetColorMask(color color.Color)

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

func (*IMDraw) SetMatrix Uses

func (imd *IMDraw) SetMatrix(m pixel.Matrix)

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.