imdraw

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 3 Imported by: 9

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndShape

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

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

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

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

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

func (imd *IMDraw) Clear()

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

func (*IMDraw) Draw

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

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

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

func (imd *IMDraw) Line(thickness float64)

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

func (*IMDraw) MakePicture

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

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

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

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

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

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

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

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

func (*IMDraw) SetMatrix

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

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

Jump to

Keyboard shortcuts

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