shape

package module
v0.0.0-...-b703096 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT, Unlicense Imports: 9 Imported by: 3

README

Shape

A library for drawing common shapes like: line, circle, rectangle and more.

Line

shape.Line{a,b,...}.Stroke(color, width, gtx)

Circle

shape.Circle{c,r}.Stroke(color, width, gtx)
shape.Circle{c,r}.Fill(color, gtx)

Rectangle

shape.Rectangle{a,b}.Stroke(color, width, gtx)
shape.Rectangle{a,b}.Fill(color, gtx)

Triangle

shape.Triangle{a,b,c}.Stroke(color, width, gtx)
shape.Triangle{a,b,c}.Fill(color, gtx)

Curve

shape.Curve{a,b,...}.Stroke(color, width,gtx)

Points

...

Example Draw Red Line

func drawLine(gtx *layout.Context) {
    red := color.RGBA{255,0,0,255}
    s := gtx.Constraints
    w, h := float32(s.Width.Max), float32(s.Height.Max)
    shape.Line{{0,h/2},{w,h/2}}.Stroke(red, width, gtx)
}

See in example folder for gio application with more examples of shapes.

Read More

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ButtCapper

func ButtCapper(offset float32, p1, p2 f32.Point) f32.Point

func DrawArc

func DrawArc(ops *op.Ops)

func Inf

func Inf(sign int) float32

func IsInf

func IsInf(f float32, sign int) bool

func IsNaN

func IsNaN(sign float32) bool

func Line2

func Line2(gtx *layout.Context, width float32, ps ...f32.Point)

func Max

func Max(x, y float32) float32

func Min

func Min(x, y float32) float32

func MitterJoiner

func MitterJoiner(path clip.Path, offset float32, p1, p2, qp3 f32.Point)

func OffsetPoints

func OffsetPoints(l Line, width float32) (offset []f32.Point)

func Overlay

func Overlay(rs ...f32.Rectangle) f32.Rectangle

func PaintPoint

func PaintPoint(p f32.Point, radius float32, gtx *layout.Context)

func PaintPoints

func PaintPoints(ps []f32.Point, radius float32, gtx *layout.Context)

func RoundCapper

func RoundCapper(offset float32, p1, p2 f32.Point) f32.Point

func RoundJoiner

func RoundJoiner(path clip.Path, offset float32, p1, p2, qp3 f32.Point)

func SquareCapper

func SquareCapper(offset float32, p1, p2 f32.Point) float32

func SquareJoiner

func SquareJoiner(path clip.Path, offset float32, p1, p2, qp3 f32.Point)

Types

type BBox

type BBox f32.Rectangle

func (BBox) Add

func (bb BBox) Add(p f32.Point) (bb2 BBox)

func (BBox) Union

func (bb BBox) Union(b BBox) (bb2 BBox)

type Canvas

type Canvas struct {
	FillColor *color.RGBA

	StrokeWidth int
	StrokeColor *color.RGBA
	StrokeStyle StrokeStyle
	// contains filtered or unexported fields
}

func (*Canvas) DrawLine

func (c *Canvas) DrawLine(p1, p2 f32.Point)

type Capper

type Capper func(offset float32, p1, p2 f32.Point) f32.Point

type Circle

type Circle struct {
	Center f32.Point
	Radius float32
}

func (Circle) Fill

func (cc Circle) Fill(col color.RGBA, gtx *layout.Context) f32.Rectangle

func (Circle) Stroke

func (cc Circle) Stroke(col color.RGBA, width float32, gtx *layout.Context) f32.Rectangle

type Cube

type Cube struct {
	Point0, Point1, Point2, Point3 f32.Point
}

type Fill

type Fill interface {
	Stroke
	Fill(rgba color.RGBA, ops *op.Ops)
}

type Joiner

type Joiner func(path clip.Path, offset float32, p1, p2, qp3 f32.Point)

type LineCap

type LineCap int
const (
	Butt LineCap = iota
	Square
)

type LineJoin

type LineJoin int
const (
	None LineJoin = iota
	Round
)

type Plus

type Plus struct{}

func (Plus) Stroke

func (p Plus) Stroke(width unit.Value, gtx *layout.Context) (box f32.Rectangle)

type Quad

type Quad struct {
	Point0, Point1, Point2 f32.Point
}

type Rectangle

type Rectangle struct {
	P1, P2 f32.Point
}

func (Rectangle) Fill

func (r Rectangle) Fill(rgba color.RGBA, gtx *layout.Context) f32.Rectangle

func (Rectangle) Stroke

func (r Rectangle) Stroke(rgba color.RGBA, lineWidth float32, gtx *layout.Context) f32.Rectangle

type Shape

type Shape interface {
	Add(ops *op.Ops)
}

type Stroke

type Stroke interface {
	Shape
	Stroke(width float32, style StrokeType, rgba color.RGBA, ops *op.Ops)
}

type StrokeStyle

type StrokeStyle int
const (
	Solid StrokeStyle = iota
	Dotted
	Dashed
)

type StrokeType

type StrokeType int

type Triangle

type Triangle struct {
	A, B, C f32.Point
}

func (Triangle) Fill

func (t Triangle) Fill(rgba color.RGBA, gtx *layout.Context) (bbox f32.Rectangle)

func (Triangle) Stroke

func (t Triangle) Stroke(rgba color.RGBA, width float32, gtx *layout.Context) (bbox f32.Rectangle)

type Vector

type Vector struct {
	// contains filtered or unexported fields
}

func (Vector) Magnitude

func (v Vector) Magnitude() float32

func (Vector) Normalize

func (v Vector) Normalize() Vector

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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