Documentation ¶
Index ¶
- Constants
- func CalculateLines(pins []Pin) [][][]image.Point
- func Circle(dst draw.Image, center Pin, radius float64, thickness float64, col color.Color)
- func ColorOver(under, over color.Color) color.Color
- func ColorOverRGBA(under, over color.RGBA) color.RGBA
- func Disk(dst draw.Image, center Pin, radius float64, col color.Color)
- func Generate(target image.Image, options ...Option) (resultImage, targetImage *image.RGBA, instructions []int, length float64, ...)
- func GetImages(size int, filename string) (targetImage, resultImage *image.RGBA, err error)
- func LinePoints(from, to Pin) []image.Point
- func OpenImageFromDisk(filename string) (image.Image, error)
- func PixelOver(dst draw.Image, pixels []image.Point, cOver color.RGBA)
- func RescaleImage(oldImg image.Image, newSize int) *image.RGBA
- func SaveImageToDisk(filename string, img image.Image) error
- func Score(points []image.Point, target, result *image.RGBA) float64
- func WriteInstructionsToDisk(filename string, instructions []int, length float64) error
- type Option
- func WithDiameter(d float64) Option
- func WithEraseColor(c color.Color) Option
- func WithEraseFactor(f float64) Option
- func WithLinesCount(n int) Option
- func WithPaintColor(c color.Color) Option
- func WithPinCount(n int) Option
- func WithPins(pins []Pin) Option
- func WithResolution(n int) Option
- func WithResultImage(img image.Image) Option
- func WithStringDarkness(d uint8) Option
- type Pin
- type ScoreFunction
Constants ¶
const AaSmoothing float64 = 1
Smothing radius for anti-aliasing. This is not used currently
Variables ¶
This section is empty.
Functions ¶
func CalculateLines ¶
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 ColorOverRGBA ¶
ColorOverRGBA blends to RGBA colors using the over method
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 ¶
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 ¶
LinePoints gets a list of points that form a line from a pin to another pin
func OpenImageFromDisk ¶
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 ¶
PixelOver draws (using the over operation) the specified color at all pixels. It is only implemented for RGBA images currently.
func RescaleImage ¶
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 ¶
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.
Types ¶
type Option ¶
type Option func(o *options) error
Options allow to modify the string image generation.
func WithDiameter ¶
WithDiameter allows to set the image diameter for an accurate string length calculation. Unit is meters.
func WithEraseColor ¶
WithEraseColor allows to define a color (with alpha) that is used to paint out the already used connections in the target image.
func WithEraseFactor ¶
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 ¶
WithLinesCount defines the number of line segments used.
func WithPaintColor ¶
WithPaintColor allows to define a certain color (including alpha) for the string
func WithPinCount ¶
WithPinCount uses pins in a circular pattern with the given number of pins.
func WithPins ¶
WithPins allows to directly provide a list of pins. Can be used to define a non-circular pattern of pins.
func WithResolution ¶
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 ¶
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 ¶
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 ¶
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.
type ScoreFunction ¶
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.