helpers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LINE_WIDTH = 0.2
)
View Source
const (
	WHITESPACE_CUTSET = " \t\n"
)

Variables

View Source
var (
	EMPTY_REGION = Rect{0, 0, 0, 0}
)
View Source
var (
	NIL_COLOR = color.RGBA{0, 0, 0, 0}
)

Functions

func DrawFilledTriangle

func DrawFilledTriangle(gc *draw2dimg.GraphicContext, pt1, pt2, pt3 Point, strokeColor, fillColor color.RGBA)

Draws a filled triangle in an image.

*pt1*: The first point of the triangle.
*pt2*: The second point of the triangle.
*pt3*: The third point of the triangle.
*strokeColor*: The color to stroke the triangle with.
*fillColor*: The color to fill the triangle with.

func DrawLine

func DrawLine(gc *draw2dimg.GraphicContext, pt1, pt2 Point, color color.RGBA)

Draws a line in an image.

*pt1*: The starting point of the line.
*pt2*: The ending point of the line.
*color*: The color to stroke the line with.

func DrawRectangle

func DrawRectangle(gc *draw2dimg.GraphicContext, x, y, width, height float64, color color.RGBA)

Draws a rectangle in an image.

*image*: The image to draw the rectangle in.
*x*: The horizontal offset of the rectangle.
*y*: The vertical offset of the rectangle.
*width*: The width of the rectangle.
*height*: The height of the rectangle.
*color*: The color to stroke the rectangle with.

func DrawTriangle

func DrawTriangle(gc *draw2dimg.GraphicContext, pt1, pt2, pt3 Point, strokeColor color.RGBA)

Draws a triangle in an image.

*pt1*: The first point of the triangle.
*pt2*: The second point of the triangle.
*pt3*: The third point of the triangle.
*strokeColor*: The color to stroke the triangle with.

func FillImage

func FillImage(image *image.RGBA, color color.RGBA)

Fills an image with color.

*image*: The image to fill.
*color*: The color to fill the image with.

func FillRectangle

func FillRectangle(gc *draw2dimg.GraphicContext, x, y, width, height float64, color color.RGBA)

Draws a filled rectangle in an image.

*image*: The image to draw the rectangle in.
*x*: The horizontal offset of the rectangle.
*y*: The vertical offset of the rectangle.
*width*: The width of the rectangle.
*height*: The height of the rectangle.
*color*: The color to fill the rectangle with.

func GetCSV

func GetCSV(text string) ([]string, error)

Retrieves a comma-separated list of values from a string

func ParseColor

func ParseColor(txt string) (color.RGBA, error)

Parses a given color value.

func ParseHexColor

func ParseHexColor(txt string) (color.RGBA, error)

Parses a hexadecimal color value.

Format of text: #[0-9a-f]{3, 12}

func ParseNameColor

func ParseNameColor(txt string) (color.RGBA, error)

Returns the color value of a predetermined color that matches the given name.

func ParseRGBColor

func ParseRGBColor(txt string) (color.RGBA, error)

Parses an rgb(a)? color value.

Format of text: rgb(\d+, \d+, \d+) or rgb(\d+, \d+, \d+)

func PutPixel

func PutPixel(gc *draw2dimg.GraphicContext, x, y float64, color color.RGBA)

Adds a pixel to an image.

*x*: The horizontal position of the pixel.
*y*: The vertical position of the pixel.

func RandomAlphaColor

func RandomAlphaColor() color.RGBA

Generates a color with random rgba values.

func RandomColor

func RandomColor() color.RGBA

Generates a color with random rgb values (a=255).

func SubString

func SubString(text string, start, end int) string

Types

type ColorPalette

type ColorPalette struct {
	Name        string       `yaml:"name"`
	Transitions []Transition `yaml:"transitions"`
}

Represents a color palette.

func ParseColorPalette

func ParseColorPalette(txt string) (ColorPalette, error)

Parses a string into a color palette.

func ParseNameColorPalette

func ParseNameColorPalette(name string) (ColorPalette, error)

Returns the color value of a predetermined color palette that matches the given name.

func (*ColorPalette) GetColor

func (palette *ColorPalette) GetColor(pos float64) (color.RGBA, error)

Gets the color value of a given position in this ColorPalette.

func (*ColorPalette) Render

func (palette *ColorPalette) Render(output io.Writer, width, height int, step float64) error

Displays an image of this palette to the given output.

func (*ColorPalette) TranslateColorTransitions

func (palette *ColorPalette) TranslateColorTransitions() error

Translate the value of the color transitions for this color palette.

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

type Rect

type Rect struct {
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

Represents a rectangular region.

func ParseRect

func ParseRect(txt string) (Rect, error)

Converts a CSV of floats to a Rect type.

type Transition

type Transition struct {
	Color string `yaml:"color"`

	Position float32 `yaml:"position"`
	// contains filtered or unexported fields
}

Represents a color transition.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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