ascii

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: MIT, 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("$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\"^`'. "),
	Reversed: false,
	Colored:  true,
}

DefaultOptions that contains the default pixels

Functions

This section is empty.

Types

type CharPixel

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

type PixelASCIIConverter struct {
}

PixelASCIIConverter responsible for pixel ascii conversion

func (PixelASCIIConverter) ConvertPixelToASCII

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

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

ConvertPixelToPixelASCII convert a image pixel to CharPixel

type PixelConverter

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

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