plot

package
v0.0.0-...-374845a Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var A4 = XY{210, 297}

Functions

func ConvertSVGToGCodeWithVpype

func ConvertSVGToGCodeWithVpype(out io.Writer, svgPath string, optFN string, flavorOverride string) error

ConvertSVGToGCodeWithVpype converts an existing SVG file into G-code using vpype's gwrite plug-in and the repo's G-code option schema.

func DecodeInteractiveState

func DecodeInteractiveState[T any]() (T, error)

func InteractiveStateRaw

func InteractiveStateRaw() (json.RawMessage, error)

func JsonPlotter

func JsonPlotter(out io.Writer, p Canvas, d Drawing) error

func PlotGCodeWithVpype

func PlotGCodeWithVpype(out io.Writer, p Canvas, d Drawing, optFN string, flavorOverride string) error

PlotGCodeWithVpype renders SVG, applies vpype post-processing, and emits G-code using the vpype-gcode plug-in. If vpype or the plug-in is missing, or if vpype fails, it falls back to the native G-code generator.

func PlotSVGWithVpype

func PlotSVGWithVpype(out io.Writer, p Canvas, d Drawing) error

PlotSVGWithVpype renders SVG and applies vpype post-processing if available. If vpype is missing or fails, it falls back to plain SVG output.

func Run

func Run(p Canvas, d DrawFunc, opts ...RunOpt)

Run executes a drawing - use this as entry point for all "sketches"

Types

type Arc

type Arc struct {
	P      XY
	Radius int
}

Arc draws an arc

type ArgSpec

type ArgSpec struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Type        ArgType  `json:"type"`
	Default     *string  `json:"default,omitempty"`
	Min         *float64 `json:"min,omitempty"`
	Max         *float64 `json:"max,omitempty"`
}

func BoolArg

func BoolArg(name string, description string, def bool) ArgSpec

func FloatArg

func FloatArg(name string, description string, min float64, max float64, def float64) ArgSpec

func IntArg

func IntArg(name string, description string, min int, max int, def int) ArgSpec

func (ArgSpec) Normalize

func (s ArgSpec) Normalize(raw string) (string, error)

type ArgType

type ArgType string
const (
	ArgTypeInt   ArgType = "int"
	ArgTypeFloat ArgType = "float"
	ArgTypeBool  ArgType = "bool"
)

type BezierCurve

type BezierCurve struct {
	ControlPoints []XY
}

BezierCurve is a drawable bezier curve

type Canvas

type Canvas struct {
	Size  XY
	DPI   int
	Bleed XY
	// PenWidth controls rendered stroke width for image/vector devices.
	// If unset or <= 0, a width of 1 is used.
	PenWidth float64
}

Canvas describes the canvas on which we'll draw

func (Canvas) Frame

func (p Canvas) Frame() []Drawable

Frame returns a frame around the canvas

func (Canvas) FrameBleed

func (p Canvas) FrameBleed() []Drawable

Frame returns a frame around the canvas respecting the bleed

func (Canvas) Inner

func (p Canvas) Inner() XY

Inner returns the plot size - 2*bleed

func (Canvas) Middle

func (p Canvas) Middle() XY

Middle returns the middle point of the canvas

func (Canvas) StrokeWidth

func (p Canvas) StrokeWidth() float64

func (Canvas) Up

func (p Canvas) Up() XY

Up returns the upper right corner respecting the bleed

func (Canvas) Zero

func (p Canvas) Zero() XY

Zero returns the zero point respecting the bleed

type Debug

type Debug struct {
	D Drawable
}

Debug helps debugging other drawables. Use `AsDebug()`.

type DrawFunc

type DrawFunc func(p Canvas, args map[string]string) (d Drawing, err error)

DrawFunc produces a new drawing

type Drawable

type Drawable interface {
	// contains filtered or unexported methods
}

Drawable marks all drawable elements

func AsDebug

func AsDebug(ds ...Drawable) []Drawable

AsDebug decorates drawables for debugging

func AsDrawable

func AsDrawable(ls ...Line) []Drawable

AsDrawable convers lines to drawables

type Drawing

type Drawing []Drawable

func OptimiseLinearLineOrder

func OptimiseLinearLineOrder(p Canvas, d Drawing) (Drawing, error)

type GCodeCommand

type GCodeCommand interface {
	fmt.Stringer
	ModifyState(*gcodeState)
}

type GCodeFlavor

type GCodeFlavor string
const (
	GCodeFlavorVanilla GCodeFlavor = "vanilla"
	GCodeFlavorMK4S    GCodeFlavor = "mk4s"
)

func ParseGCodeFlavor

func ParseGCodeFlavor(v string) (GCodeFlavor, error)

type GCodeLift

type GCodeLift struct {
	Height   int
	Feedrate int
}

func (GCodeLift) ModifyState

func (l GCodeLift) ModifyState(s *gcodeState)

func (GCodeLift) String

func (l GCodeLift) String() string

type GCodeLinearMoveXY

type GCodeLinearMoveXY struct {
	P        XY
	Feedrate int
	Scale    float64
}

func (GCodeLinearMoveXY) ModifyState

func (l GCodeLinearMoveXY) ModifyState(s *gcodeState)

func (GCodeLinearMoveXY) String

func (l GCodeLinearMoveXY) String() string

type GCodeOpts

type GCodeOpts struct {
	DrawFeed   int     `json:"drawFeed"`
	DrawLift   int     `json:"drawLift"`
	TravelFeed int     `json:"travelFeed"`
	TravelLift int     `json:"travelLift"`
	Scale      float64 `json:"scale"`
	Offset     XY      `json:"offset"`
	Flavor     string  `json:"flavor,omitempty"`
}

func LoadGCodeOpts

func LoadGCodeOpts(optFN string, flavorOverride string) (*GCodeOpts, error)

func NewDefaultGCodeOpts

func NewDefaultGCodeOpts() *GCodeOpts

type InteractiveAction

type InteractiveAction struct {
	Tool   string `json:"tool"`
	Region string `json:"region"`
}

type InteractiveApplyResult

type InteractiveApplyResult struct {
	State json.RawMessage `json:"state,omitempty"`
}

type InteractiveCanvas

type InteractiveCanvas struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

type InteractiveHooks

type InteractiveHooks struct {
	Describe func(p Canvas, args map[string]string, state json.RawMessage) (InteractiveManifest, error)
	Apply    func(p Canvas, args map[string]string, state json.RawMessage, action InteractiveAction) (json.RawMessage, error)
}

type InteractiveManifest

type InteractiveManifest struct {
	Canvas      InteractiveCanvas   `json:"canvas"`
	Tools       []InteractiveTool   `json:"tools"`
	Regions     []InteractiveRegion `json:"regions"`
	DefaultTool string              `json:"defaultTool,omitempty"`
}

type InteractiveRegion

type InteractiveRegion struct {
	ID        string `json:"id"`
	X         int    `json:"x"`
	Y         int    `json:"y"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Label     string `json:"label,omitempty"`
	Hint      string `json:"hint,omitempty"`
	Stroke    string `json:"stroke,omitempty"`
	Fill      string `json:"fill,omitempty"`
	TextColor string `json:"textColor,omitempty"`
}

type InteractiveTool

type InteractiveTool struct {
	ID          string `json:"id"`
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
}

type Line

type Line struct {
	Start XY
	End   XY
}

Line is a drawable line

func (Line) Offset

func (l Line) Offset(p XY) Line

Offset adds the point to start and end point

type OptimisationFunc

type OptimisationFunc func(p Canvas, d Drawing) (Drawing, error)

type PlotFunc

type PlotFunc func(out io.Writer, p Canvas, d Drawing) error

PlotFunc plots a drawing to some output device

func NewGCodePlotter

func NewGCodePlotter(optFN string, flavorOverride string) (PlotFunc, error)

func NewPNGPlotter

func NewPNGPlotter() PlotFunc

func NewSVGPlotter

func NewSVGPlotter() PlotFunc

NewSVGPlotter returns a PlotFunc that writes SVG output.

type RunConfig

type RunConfig struct {
	ArgsSchema  []ArgSpec
	Interactive *InteractiveHooks
}

type RunOpt

type RunOpt func(*RunConfig)

func WithArgSchema

func WithArgSchema(specs ...ArgSpec) RunOpt

func WithArgsSchema

func WithArgsSchema(specs ...ArgSpec) RunOpt

func WithInteractive

func WithInteractive(h InteractiveHooks) RunOpt

type XY

type XY struct {
	X int
	Y int
}

XY represents XY coordinates

func (XY) Add

func (xy XY) Add(x, y int) XY

Add adds to the coordinates

func (XY) AddF

func (xy XY) AddF(x, y float64) XY

AddF adds floats which are cast to int beforehand

func (XY) AddXY

func (xy XY) AddXY(other XY) XY

AddXY adds another XY pair

func (XY) Div

func (xy XY) Div(f int) XY

Div divides coordinates

func (XY) IsZero

func (xy XY) IsZero() bool

IsZero returns true if the XY is the zero value

func (XY) Mult

func (xy XY) Mult(f int) XY

Mult multiplies coordinates

Jump to

Keyboard shortcuts

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