ascii

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package ascii can convert a image pixel to a raw char base on it's RGBA value, in another word, input a image pixel output a raw char ascii.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Pixels:   []byte(" .,:;i1tfLCG08@"),
	Reversed: false,
	Colored:  true,
}

DefaultOptions that contains the default pixels

Functions

This section is empty.

Types

type CharPixel added in v1.0.1

type CharPixel struct {
	Char byte
	R    uint8
	G    uint8
	B    uint8
	A    uint8
}

CharPixel is converted pixel ascii

type Options

type Options struct {
	Pixels   []byte
	Reversed bool
	Colored  bool
}

Options convert pixel to raw char

func NewOptions

func NewOptions() Options

NewOptions create a new convert option

type PixelASCIIConverter added in v1.0.1

type PixelASCIIConverter struct {
}

PixelASCIIConverter responsible for pixel ascii conversion

func (PixelASCIIConverter) ConvertPixelToASCII added in v1.0.1

func (converter PixelASCIIConverter) ConvertPixelToASCII(pixel color.Color, options *Options) string

ConvertPixelToASCII converts a pixel to a ASCII char string

Example

ExampleConvertPixelToASCII is a example convert pixel to ascii char

converter := NewPixelConverter()
// Create the pixel
r, g, b, a := uint8(255), uint8(255), uint8(255), uint8(255)
pixel := color.RGBA{
	R: r,
	G: g,
	B: b,
	A: a,
}

// Create the convert options
defaultOptions := NewOptions()
defaultOptions.Colored = false
convertedChar := converter.ConvertPixelToASCII(pixel, &defaultOptions)
fmt.Println(convertedChar)
Output:

@

func (PixelASCIIConverter) ConvertPixelToPixelASCII added in v1.0.1

func (converter PixelASCIIConverter) ConvertPixelToPixelASCII(pixel color.Color, options *Options) CharPixel

ConvertPixelToPixelASCII convert a image pixel to CharPixel

type PixelConverter added in v1.0.1

type PixelConverter interface {
	ConvertPixelToASCII(pixel color.Color, options *Options) string
	ConvertPixelToPixelASCII(pixel color.Color, options *Options) CharPixel
}

PixelConverter define the convert pixel operation

func NewPixelConverter added in v1.0.1

func NewPixelConverter() PixelConverter

NewPixelConverter create a new pixel converter

Jump to

Keyboard shortcuts

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