stringer

package
v0.0.0-...-df43766 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const AaSmoothing float64 = 1

Smothing radius for anti-aliasing. This is not used currently

Variables

This section is empty.

Functions

func CalculateLines

func CalculateLines(pins []Pin) [][][]image.Point

CalculateLines takes a list of pins and then pre-calculates all pixels that lie on a line between all possible pin pairs. The list of pixels will be nil, if the pins are too close together to reduce the occurence of very short strings.

func Circle

func Circle(dst draw.Image, center Pin, radius float64, thickness float64, col color.Color)

Circle draws a circle with radius and thickness at the pin location

func ColorOver

func ColorOver(under, over color.Color) color.Color

ColorOver blends to colors regardless of type using the over method

func ColorOverRGBA

func ColorOverRGBA(under, over color.RGBA) color.RGBA

ColorOverRGBA blends to RGBA colors using the over method

func Disk

func Disk(dst draw.Image, center Pin, radius float64, col color.Color)

Disk draws a solid disk at pin location

func Generate

func Generate(target image.Image, options ...Option) (resultImage, targetImage *image.RGBA, instructions []int, length float64, err error)

Generate will use a target image to calculate a string image and return the result image, the possibly altered target image (if options like WithEraseFactor are used), the order of pins to use and the length of string. An error will be returned, if one of the given options is used incorrectly.

func GetImages

func GetImages(size int, filename string) (targetImage, resultImage *image.RGBA, err error)

GetImages creates from a filename and a resolution a square target image and a white (empty) result image to process using the Generate function.

func LinePoints

func LinePoints(from, to Pin) []image.Point

LinePoints gets a list of points that form a line from a pin to another pin

func OpenImageFromDisk

func OpenImageFromDisk(filename string) (image.Image, error)

OpenImageFromDisk can be used to create an image.Image by opening a file. It returns the image or the error of the os.Open or image.Decode function calls.

func PixelOver

func PixelOver(dst draw.Image, pixels []image.Point, cOver color.RGBA)

PixelOver draws (using the over operation) the specified color at all pixels. It is only implemented for RGBA images currently.

func RescaleImage

func RescaleImage(oldImg image.Image, newSize int) *image.RGBA

RescaleImage takes an image and a size and will create an RGBA image with square dimensions. The input image will always be cropped to square aspect ratio and scaled using nearest neighbour algorithm.

func SaveImageToDisk

func SaveImageToDisk(filename string, img image.Image) error

SaveImageToDisk will save an image.Image to the given file. If there are errors creating the file or encoding the image the error is returned.

func Score

func Score(points []image.Point, target, result *image.RGBA) float64

Score is the default scoring function.

func WriteInstructionsToDisk

func WriteInstructionsToDisk(filename string, instructions []int, length float64) error

WriteInstructionsToDisk writes the instructions (a list of pin IDs) to a text file, including the length of string required. If there is an error creating the file, it is returend.

Types

type Option

type Option func(o *options) error

Options allow to modify the string image generation.

func WithDiameter

func WithDiameter(d float64) Option

WithDiameter allows to set the image diameter for an accurate string length calculation. Unit is meters.

func WithEraseColor

func WithEraseColor(c color.Color) Option

WithEraseColor allows to define a color (with alpha) that is used to paint out the already used connections in the target image.

func WithEraseFactor

func WithEraseFactor(f float64) Option

WithEraseFactor allows to paint out a ceratin fraction of the painted line. Can be useful to control contrast in the final result. It always uses white to paint out the lines. Otherwise use WithEraseColor.

func WithLinesCount

func WithLinesCount(n int) Option

WithLinesCount defines the number of line segments used.

func WithPaintColor

func WithPaintColor(c color.Color) Option

WithPaintColor allows to define a certain color (including alpha) for the string

func WithPinCount

func WithPinCount(n int) Option

WithPinCount uses pins in a circular pattern with the given number of pins.

func WithPins

func WithPins(pins []Pin) Option

WithPins allows to directly provide a list of pins. Can be used to define a non-circular pattern of pins.

func WithResolution

func WithResolution(n int) Option

WithResolution controls the pixel size of the output image. More pixels allow for more pleasant preview, but a lower resolution might yield a better representation with physical string as fewer "buckets" for darkening the image are available.

func WithResultImage

func WithResultImage(img image.Image) Option

WithResultImage can be used to start the process with a non-empty result image. This can be useful, of a previous generation shall be continued.

func WithStringDarkness

func WithStringDarkness(d uint8) Option

WithStringDarkness allows to set a custom string darkness, e.g. to control how often the same line will be used.

type Pin

type Pin struct {
	X, Y float64
}

Pin describes the location of a pin where string can be wrapped around.

func CalculatePins

func CalculatePins(n int, bounds image.Rectangle, padding int) []Pin

CalculatePins takes the number of pins, the image boundary and a padding around the edges and calculates the pin locations in a circular pattern. Some randomness is added to prevent or reduce ringing patterns.

func (Pin) Draw

func (p Pin) Draw(img draw.Image)

Draw will indicate the pin location in the image with a red disk.

type ScoreFunction

type ScoreFunction func([]image.Point, *image.RGBA, *image.RGBA) float64

ScoreFunction defines functions, that can be used do calculate the score of a number of points against a target and a result image. Used e.g. with LinePoints to evaluate the possible lines and decide where to draw the next line.

func ScoreWithColors

func ScoreWithColors(paintColor, eraseColor color.Color) ScoreFunction

ScoreWithColors shall take into account the color of the line that is to be drawn. it is not yet properly implemented.

Jump to

Keyboard shortcuts

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