draw

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

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package draw 提供简单的绘图工具

Index

Constants

View Source
const (
	White = WhiteColor(0xFF)
	Black = BlackColor(0xFF)
	Red   = RedColor(0xFF)
	Green = GreenColor(0xFF)
	Blue  = BlueColor(0xFF)
)

Red 表示简单红色

Variables

This section is empty.

Functions

func DrawHollowCircleXY

func DrawHollowCircleXY[TC, TR, TW Number](canvas Canvas, centerX, centerY TC, radius TR, width TW)

DrawHollowCircle 封装 DrawHollowCircle, 但是提供具体的 XY 值而不是 Point

func DrawHollowRectXY

func DrawHollowRectXY[TP, TW Number](canvas Canvas, x1, y1, x2, y2 TP, width TW)

DrawHollowRectXY 封装 DrawHollowRect, 但是提供具体的 XY 值而不是 Point

func DrawLineXY

func DrawLineXY[TP, TW Number](canvas Canvas, x1, y1, x2, y2 TP, width TW)

DrawLineXY 封装 DrawLine, 但是提供具体的 XY 值而不是 Point

func DrawPointXY

func DrawPointXY[TP, TR Number](canvas Canvas, centerX, centerY TP, radius TR)

DrawPointXY 封装 DrawPoint, 但是提供具体的 XY 值而不是 Point

func DrawSolidRectXY

func DrawSolidRectXY[T Number](canvas Canvas, x1, y1, x2, y2 T)

DrawSolidRectXY 封装 DrawSolidRect, 但是提供具体的 XY 值而不是 Point

func DrawTextXY

func DrawTextXY[T Number](canvas TextCanvas, x, y T, text string, opts ...Option)

DrawTextXY 封装 DrawText, 但是提供具体的 XY 值而不是 Point

Types

type BlackColor

type BlackColor uint8

func (BlackColor) RGBA

func (bc BlackColor) RGBA() (r, g, b, a uint32)

RGBA 实现 color.Color 接口

type BlueColor

type BlueColor uint8

func (BlueColor) RGBA

func (bl BlueColor) RGBA() (r, g, b, a uint32)

RGBA 实现 color.Color 接口

type Canvas

type Canvas interface {
	Size() (width, height float64)

	SetDrawColor(clr color.Color)
	CurrentDrawColor() color.Color

	DrawPoint(center Point, radius float64)
	DrawHollowCircle(center Point, radius, width float64)

	DrawLine(from, to Point, width float64)

	DrawHollowRect(endpoint1, endpoint2 Point, width float64)
	DrawSolidRect(endpoint1, endpoint2 Point)

	DrawHollowPolygon(width float64, endpoints ...Point)
	DrawSolidPolygon(endpoints ...Point)

	Save(filepath string) error
}

Canvas 表示一个画板

type GreenColor

type GreenColor uint8

func (GreenColor) RGBA

func (gr GreenColor) RGBA() (r, g, b, a uint32)

RGBA 实现 color.Color 接口

type MergedOptions

type MergedOptions interface {
	Color() color.Color
	FontSize() int
	Rotate() float64
}

MergedOptions 表示合并后的参数。调用方无需使用,这是给实现用的

func MergeOptions

func MergeOptions(c Canvas, opts []Option) MergedOptions

MergeOptions 给实现方使用, 实现各种 option

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

Number 表示任意数字类型

type Option

type Option func(o *optImpl)

Option 表示额外参数

func OptColor

func OptColor(clr color.Color) Option

OptColor 指定此次绘制颜色

func OptFontSize

func OptFontSize[T Number](size T) Option

OptFontSize 指定字号

func OptRotate

func OptRotate[T Number](angle T) Option

OptRotate 指定旋转角度

type Point

type Point struct {
	X float64
	Y float64
}

Point 表示一个点

func NewPoint

func NewPoint[T1, T2 Number](x T1, y T2) Point

NewPoint 构建一个新的点

func P

func P[T1, T2 Number](x T1, y T2) Point

P 等价于 NewPoint, 缩短调用方调用长度

type RedColor

type RedColor uint8

func (RedColor) RGBA

func (re RedColor) RGBA() (r, g, b, a uint32)

RGBA 实现 color.Color 接口

type TextCanvas

type TextCanvas interface {
	DrawText(origin Point, text string, opts ...Option)
}

TextCanvas 表示一个能绘图的画布

type WhiteColor

type WhiteColor uint8

func (WhiteColor) RGBA

func (wc WhiteColor) RGBA() (r, g, b, a uint32)

RGBA 实现 color.Color 接口

Directories

Path Synopsis
Package svg 提供基于 svg 的绘图工具
Package svg 提供基于 svg 的绘图工具

Jump to

Keyboard shortcuts

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