draw

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arrow

func Arrow(ctx Ctx, pt d2.Pt, v d2.V)

func BoxModel

func BoxModel(ctx Ctx, model boxmodel.BoxModel)

BoxModel is rendered as a solid

func Call

func Call(gen func() *Context, funcs ...func(*Context))

Call is a helper function that uses relection for generating images. It needs a Context generator. For each function passed in, a go routine starts that generates a context and passes into the function, then the image is saved with the name of the function.

func Color

func Color(r, g, b float64) color.Color

Color is a helper for defining colors using percentages.

func OnPt1

func OnPt1(ctx Ctx, pt1 d2.Pt1, ts []float64, radius float64)

OnPt1 draws circles on the d2.Pt1 for each value in ts.

func Pt1

func Pt1(ctx Ctx, pt1 d2.Pt1, r iter.FloatRange)

Pt1 draws a curve that fulfills d2.Pt1.

func Pt2

func Pt2(ctx Ctx, pt2 d2.Pt2, r0, r1 iter.FloatRange)

Pt2 draws a d2.Pt2 as stripes

func V1

func V1(ctx Ctx, pt1 d2.Pt1, r iter.FloatRange, scale float64)

V1 draws a curve with arrows indicating the derivative

Types

type Context

type Context struct {
	Ctx
	iter.FloatRange
	PointSize float64
}

Context passes in the Ctx and FloatRange to simplify calling the draw functions.

func (*Context) Arrow

func (c *Context) Arrow(pt d2.Pt, v d2.V)

func (*Context) BoxModel

func (c *Context) BoxModel(model boxmodel.BoxModel)

func (*Context) Circle

func (c *Context) Circle(pt d2.Pt, radius float64)

func (*Context) LinePts

func (c *Context) LinePts(pts ...d2.Pt)

LinePts draws line segments connecting the points.

func (*Context) OnPt1

func (c *Context) OnPt1(pt1 d2.Pt1, ts []float64, radius float64)

func (*Context) Pt1

func (c *Context) Pt1(pt1 d2.Pt1)

func (*Context) Pt2

func (c *Context) Pt2(pt2 d2.Pt2, r iter.FloatRange)

func (*Context) Pts

func (c *Context) Pts(pts ...d2.Pt)

Pts draws a circle at each point with a diamter of Context.PointSize.

func (*Context) V1

func (c *Context) V1(pt1 d2.Pt1, r iter.FloatRange, scale float64)

type ContextGenerator

type ContextGenerator struct {
	Size       grid.Pt
	Clear, Set color.Color
	PointSize  float64
}

ContextGenerator is a helper for generating Contexts

func (*ContextGenerator) Generate

func (g *ContextGenerator) Generate() *Context

Generate a Context of the defined size, set the background color and set the active color.

func (*ContextGenerator) GenerateForCtx

func (g *ContextGenerator) GenerateForCtx(ctx *gg.Context) *Context

GenerateForCtx clears the gg.Context and uses it as Ctx in the returned Context.

func (*ContextGenerator) GenerateForImage

func (g *ContextGenerator) GenerateForImage(img image.Image) *Context

GenerateForImage takes in an image and returns a Context. If img is nil, a call to Generate is returned.

type Ctx

type Ctx interface {
	Stroke()
	Fill()
	DrawLine(x1, y1, x2, y2 float64)
	DrawRectangle(x, y, w, h float64)
	SetLineWidth(lineWidth float64)
	DrawCircle(x, y, r float64)
	SavePNG(string) error
	SetRGB(r, g, b float64)
	Image() image.Image
}

Ctx is meant to represent *gg.Context.

Jump to

Keyboard shortcuts

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