blocked

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2025 License: MIT Imports: 12 Imported by: 0

README

blocked

Package blocked provides unicode block encoding for binary data.

Unit Tests Go Reference Releases Discord Discussion

Overview

Enables displaying binary bit data using Unicode blocks such as sextants, octants, braille, or other block Type's.

The following block types are currently supported:

Description Def
Singles (1x1 blocks)
Solids Full block ( , )
Binaries Binary digits (0, 1)
XXs Binary mask characters ( , X)
Doubles (0.5x1 blocks)
Doubles Doubled full block ( , )
Splits (1x2 blocks)
Halves Half blocks
ASCIIs ASCII-safe characters ( , ^, v, %)
Quads (2x2 blocks)
Quads Quarter blocks
QuadsSeparated Quarter blocks, separated
Sextants (2x3 blocks)
Sextants Sextant blocks
SextantsSeparated Sextant blocks, separated
Octants (2x4 blocks)
Octants Octant blocks (Unicode-16)
Braille Braille glyphs

Using

Install in the usual Go fashion:

$ go get -u github.com/kenshaw/blocked@latest

Example

package main

import (
	"bytes"
	"fmt"
	"math/rand"
	"strings"

	"github.com/kenshaw/blocked"
)

func main() {
	for i, seed := range []int{
		999,
		4000,
		12555,
	} {
		if i != 0 {
			fmt.Println()
		}

		// create random data
		r := rand.New(rand.NewSource(int64(seed)))
		height := 1 + r.Intn(12)
		data := make([]uint64, height)
		for i := range height {
			data[i] = r.Uint64()
		}

		// create bitmap from data, using 64 bits per line (the width of
		// uint64)
		img, err := blocked.New(data, 64)
		if err != nil {
			panic(err)
		}

		// note: to interpret data as 46 bits wide (or another bit width) do
		// the following:
		//
		// img, err := blocked.New(data, 46)

		// encode as blocks and display
		for j, typ := range []blocked.Type{
			blocked.Solids,
			blocked.Halves,
			blocked.Sextants,
			blocked.Octants,
			blocked.Braille,
		} {
			if j != 0 {
				fmt.Println()
			}
			fmt.Printf("%d%c. %s:\n", i+1, 'a'+j, typ)
			var buf bytes.Buffer
			if err := img.Encode(&buf, typ); err != nil {
				panic(err)
			}

			// usually this would suffice:
			// fmt.Println(buf.String())

			// to work around comment formatting issues in Go examples, add
			// pipes to surround the output:
			s := "|" + strings.ReplaceAll(buf.String(), "\n", "|\n|") + "|"
			fmt.Println(s)
		}

		fmt.Println()

		// block type's values (see: `go doc blocked.Auto`) can be used as
		// formatting verbs in calls to fmt.Printf and other fmt.* funcs:
		fmt.Printf("%df. Auto:\n%v\n", i+1, img)
	}
}

Output:

1a. Solids:
|██  ██████  ██ █ █ ██  ██ █    █ ██ █  █  ██ █ █  █    ███ █████|

1b. Halves:
|▀▀  ▀▀▀▀▀▀  ▀▀ ▀ ▀ ▀▀  ▀▀ ▀    ▀ ▀▀ ▀  ▀  ▀▀ ▀ ▀  ▀    ▀▀▀ ▀▀▀▀▀|

1c. Sextants:
|🬂 🬂🬂🬂 🬂🬁🬁🬁🬀🬁🬀🬀 🬁🬁🬀🬀🬁 🬂🬁🬁 🬀 🬁🬂🬁🬂🬂|

1d. Octants:
|🮂 🮂🮂🮂 🮂𜺫𜺫𜺫𜺨𜺫𜺨𜺨 𜺫𜺫𜺨𜺨𜺫 🮂𜺫𜺫 𜺨 𜺫🮂𜺫🮂🮂|

1e. Braille:
|⠉⠀⠉⠉⠉⠀⠉⠈⠈⠈⠁⠈⠁⠁⠀⠈⠈⠁⠁⠈⠀⠉⠈⠈⠀⠁⠀⠈⠉⠈⠉⠉|

1f. Auto:
██  ██████  ██ █ █ ██  ██ █    █ ██ █  █  ██ █ █  █    ███ █████

2a. Solids:
|█████  ████ █  █ █ █    █   █    █████ █  █ █ █   ███ ████ █ ███|
| ██ ██ ██   ██ █     █   █   ███    █   █ █  ███ ██ ██    ██   █|
|█  █ ███ ████ ██  █  █ ██ █ █    ██ █  ██   ██ ████ ██  █ █   █ |
|███    █  ██ ████   ███ █     █ █ ███ ███ █      ███  █     ███ |
| ████  ███  █ █  ██ █   █ █  ████ █ ███ █ █████      █ ████ ██ █|
|  █     █ █    ███ █  ██     █ █ ██ █████        █  ████  █ ██  |

2b. Halves:
|▀██▀█▄ ██▀▀ █▄ █ ▀ ▀ ▄  ▀▄  ▀▄▄▄ ▀▀▀█▀ ▀▄ █ ▀▄█▄ ▄█▀█▄▀▀▀▀▄█ ▀▀█|
|█▄▄▀ ▀▀█ ▀██▀▄██▄ ▀ ▄█▄▀█ ▀ ▀ ▄ ▄▀█▄█ ▄██ ▄ ▀▀ ▀▀██▄▀▀▄ ▀ ▀ ▄▄█ |
| ▀█▀▀  ▀█▀▄ ▀ ▀▄▄█▀▄▀ ▄▄▀ ▀  █▀█▀▄█ ███▄█ ▀▀▀▀▀  ▄  ▄█▄█▀▀█ ██ ▀|

2c. Sextants:
|🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙|
|🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈|

2d. Octants:
|𜷆𜵘𜴤𜶦𜴟𜷛𜶍▟𜴷𜴋𜷓𜵑𜵌𜴉𜴑𜵁𜵓𜶾𜵊𜷍𜵈𜴺𜴰𜴤𜶤𜷂𜴴𜴸𜴌𜴖𜶭𜵍|
|𜺫𜴂𜺨𜺫𜴂𜴀𜺨𜴄𜴈𜴄𜺨𜴆𜺨𜺨▝𜴅𜴄▘▀𜴇▘🮂🮂𜺨𜴃 𜴈𜴈🮂▘▀𜺫|

2e. Braille:
|⣝⡫⠳⢼⠫⣥⢗⣼⡈⠌⣰⡠⡕⠄⠕⡒⡨⣍⡏⣨⡆⡃⠵⠳⢴⣏⠷⡉⠍⠞⣈⡝|
|⠈⠋⠁⠈⠋⠂⠁⠑⠚⠑⠁⠒⠁⠁⠘⠙⠑⠃⠛⠓⠃⠉⠉⠁⠐⠀⠚⠚⠉⠃⠛⠈|

2f. Auto:
🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙
🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈

3a. Solids:
|█   █  ██  ██    █ ██ █   █ ██ █ █     ██  █ █ ██ █ █  ████   ██|
|███ ██ █  █   ██ █  ███     █ █ ███    ████ ██ ███ ███  ██      |
| █ █ █ █  █  ██ █ ███ █  █   █ █ █  ██ █  ████████    ██ ███   █|
|█ ██   █ ███    ██ █      ████ ██  █ ███ █    ███  ██  ████ ███ |
| ██   ██ ██  ██ █  ██  █       ██ ██ █ █ ██  █   ████ █ █  █  █ |
|█ █ ██ █ ███  ██ █ ███ █ █ █ █ ████   ██     █ ██ █   ███  █ ███|
| █   ████  █  ███ █ ██    ██ ██ ████ █   ██  █   █ ███ ██      █|
| █  █████████ █    █  █  ██ █ █      █     ███ █  █ █  █ █    █ |
|█ █ █ █ ████ ██  █ ███ █  ██      █     ████   ██  ████ ██  ██  |
| █ ████  █ ████ █ ██ ███  █  █ █  ████  █       █ ██    ███  ███|
| █  █    █ █  █ █  █    █         ███  █  █    █    █  █   █ ██ |
|█    █ █ ██    █ ███ ███ █   ██      █  ████ █ █  ██ ███ ███ █ █|

3b. Halves:
|█▄▄ █▄ █▀ ▄▀▀ ▄▄ █ ▀█▄█   ▀ █▀▄▀▄█▄    ██▄▄▀▄█ ██▄▀▄█▄ ▀██▀   ▀▀|
|▄▀▄█ ▀ █ ▄█▄ ▀▀ █▄▀█▀ ▀  ▀▄▄▄█ █▄▀ ▄▀█▄█ ▄▀▀▀▀███▀ ▄▄ ▀█▄██▀▄▄▄▀|
|▄▀█ ▄▄▀█ ██▄ ▀█▄▀▄ ██▄ █ ▄ ▄ ▄ ██▄█▀ ▀▄█ ▀▀  █ ▄▄▀█▀▀ █▄█  █ ▄█▄|
| █  ▄████▄▄█▄ █▀▀ ▀▄▀▀▄  ▄█▀▄▀█ ▀▀▀▀ █   ▀▀▄▄█ ▄ ▀▄▀█▀ █▀▄    ▄▀|
|▀▄▀▄█▄█ ▀█▀█▄██ ▄▀▄█▀█▄█  █▀ ▄ ▄  █▄▄▄  █▀▀▀   ▀█ ▄█▀▀▀ ██▄ ▀█▄▄|
|▄▀  ▀▄ ▄ █▄▀  ▀▄▀▄▄█ ▄▄▄▀▄   ▄▄   ▀▀▀▄ ▀▄▄█▄ ▄ █  ▄▄▀▄▄█ ▄▄█ █▀▄|

3c. Sextants:
|🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡|
|🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲|
|🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅|
|🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥|

3d. Octants:
|𜵞𜷏𜴤▐𜵱𜷁𜴙𜴔𜷅𜶞𜴕𜴍𜴘𜶬𜷒𜶔𜵟𜵴𜶜𜷕𜵽𜴭𜴵▟𜵮𜵹𜵂𜶞𜷚𜵢▂𜵔|
|𜶔▘𜷗𜷣𜷅𜷘𜴷𜵮𜴑𜶊𜴴𜴿𜵸𜵩𜵙▞𜴴𜴮𜶑𜴈𜴚𜶁𜷕𜵸𜴞𜵘𜵢𜶚𜶅▝𜴃𜵞|
|𜵚𜴄𜶍𜵵𜶘𜵜𜴈𜶅𜶆𜷙𜵻𜶹𜶀𜴂𜵸𜴽 𜴴𜶌𜴘𜶲𜶾𜺠𜶑▘𜶹𜶃𜷌𜵿𜷏𜶘𜶌|

3e. Braille:
|⡳⣢⠳⢸⢁⣎⠡⠖⣜⢬⠗⠇⠠⣁⣫⢪⡺⢂⢤⣸⢓⠮⠾⣼⡷⢑⡓⢬⣻⡥⣀⡩|
|⢪⠃⣲⣽⣜⣳⡈⡷⠕⢜⠷⡘⢐⡴⡰⡜⠷⠯⢨⠚⠨⢅⣸⢐⠪⡫⡥⢳⢇⠘⠐⡳|
|⡱⠑⢗⢃⢹⡹⠚⢇⢎⣺⢙⣚⢄⠋⢐⡐⠀⠷⢖⠠⣋⣍⢀⢨⠃⣚⢍⣡⢛⣢⢹⢖|

3f. Auto:
🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡
🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲
🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅
🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥

The following sites/issues/code/... were referenced during development:

Documentation

Overview

Package blocked provides a block encoder and decoder for bitmaps.

Example
package main

import (
	"bytes"
	"fmt"
	"math/rand"
	"strings"

	"github.com/kenshaw/blocked"
)

func main() {
	for i, seed := range []int{
		999,
		4000,
		12555,
	} {
		if i != 0 {
			fmt.Println()
		}

		// create random data
		r := rand.New(rand.NewSource(int64(seed)))
		height := 1 + r.Intn(12)
		data := make([]uint64, height)
		for i := range height {
			data[i] = r.Uint64()
		}

		// create bitmap from data, using 64 bits per line (the width of
		// uint64)
		img, err := blocked.New(data, 64)
		if err != nil {
			panic(err)
		}

		// note: to interpret data as 46 bits wide (or another bit width) do
		// the following:
		//
		// img, err := blocked.New(data, 46)

		// encode as blocks and display
		for j, typ := range []blocked.Type{
			blocked.Solids,
			blocked.Halves,
			blocked.Sextants,
			blocked.Octants,
			blocked.Braille,
		} {
			if j != 0 {
				fmt.Println()
			}
			fmt.Printf("%d%c. %s:\n", i+1, 'a'+j, typ)
			var buf bytes.Buffer
			if err := img.Encode(&buf, typ); err != nil {
				panic(err)
			}

			// usually this would suffice:
			// fmt.Println(buf.String())

			// to work around comment formatting issues in Go examples, add
			// pipes to surround the output:
			s := "|" + strings.ReplaceAll(buf.String(), "\n", "|\n|") + "|"
			fmt.Println(s)
		}

		fmt.Println()

		// block type's values (see: `go doc blocked.Auto`) can be used as
		// formatting verbs in calls to fmt.Printf and other fmt.* funcs:
		fmt.Printf("%df. Auto:\n%v\n", i+1, img)
	}
}
Output:

1a. Solids:
|██  ██████  ██ █ █ ██  ██ █    █ ██ █  █  ██ █ █  █    ███ █████|

1b. Halves:
|▀▀  ▀▀▀▀▀▀  ▀▀ ▀ ▀ ▀▀  ▀▀ ▀    ▀ ▀▀ ▀  ▀  ▀▀ ▀ ▀  ▀    ▀▀▀ ▀▀▀▀▀|

1c. Sextants:
|🬂 🬂🬂🬂 🬂🬁🬁🬁🬀🬁🬀🬀 🬁🬁🬀🬀🬁 🬂🬁🬁 🬀 🬁🬂🬁🬂🬂|

1d. Octants:
|🮂 🮂🮂🮂 🮂𜺫𜺫𜺫𜺨𜺫𜺨𜺨 𜺫𜺫𜺨𜺨𜺫 🮂𜺫𜺫 𜺨 𜺫🮂𜺫🮂🮂|

1e. Braille:
|⠉⠀⠉⠉⠉⠀⠉⠈⠈⠈⠁⠈⠁⠁⠀⠈⠈⠁⠁⠈⠀⠉⠈⠈⠀⠁⠀⠈⠉⠈⠉⠉|

1f. Auto:
██  ██████  ██ █ █ ██  ██ █    █ ██ █  █  ██ █ █  █    ███ █████

2a. Solids:
|█████  ████ █  █ █ █    █   █    █████ █  █ █ █   ███ ████ █ ███|
| ██ ██ ██   ██ █     █   █   ███    █   █ █  ███ ██ ██    ██   █|
|█  █ ███ ████ ██  █  █ ██ █ █    ██ █  ██   ██ ████ ██  █ █   █ |
|███    █  ██ ████   ███ █     █ █ ███ ███ █      ███  █     ███ |
| ████  ███  █ █  ██ █   █ █  ████ █ ███ █ █████      █ ████ ██ █|
|  █     █ █    ███ █  ██     █ █ ██ █████        █  ████  █ ██  |

2b. Halves:
|▀██▀█▄ ██▀▀ █▄ █ ▀ ▀ ▄  ▀▄  ▀▄▄▄ ▀▀▀█▀ ▀▄ █ ▀▄█▄ ▄█▀█▄▀▀▀▀▄█ ▀▀█|
|█▄▄▀ ▀▀█ ▀██▀▄██▄ ▀ ▄█▄▀█ ▀ ▀ ▄ ▄▀█▄█ ▄██ ▄ ▀▀ ▀▀██▄▀▀▄ ▀ ▀ ▄▄█ |
| ▀█▀▀  ▀█▀▄ ▀ ▀▄▄█▀▄▀ ▄▄▀ ▀  █▀█▀▄█ ███▄█ ▀▀▀▀▀  ▄  ▄█▄█▀▀█ ██ ▀|

2c. Sextants:
|🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙|
|🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈|

2d. Octants:
|𜷆𜵘𜴤𜶦𜴟𜷛𜶍▟𜴷𜴋𜷓𜵑𜵌𜴉𜴑𜵁𜵓𜶾𜵊𜷍𜵈𜴺𜴰𜴤𜶤𜷂𜴴𜴸𜴌𜴖𜶭𜵍|
|𜺫𜴂𜺨𜺫𜴂𜴀𜺨𜴄𜴈𜴄𜺨𜴆𜺨𜺨▝𜴅𜴄▘▀𜴇▘🮂🮂𜺨𜴃 𜴈𜴈🮂▘▀𜺫|

2e. Braille:
|⣝⡫⠳⢼⠫⣥⢗⣼⡈⠌⣰⡠⡕⠄⠕⡒⡨⣍⡏⣨⡆⡃⠵⠳⢴⣏⠷⡉⠍⠞⣈⡝|
|⠈⠋⠁⠈⠋⠂⠁⠑⠚⠑⠁⠒⠁⠁⠘⠙⠑⠃⠛⠓⠃⠉⠉⠁⠐⠀⠚⠚⠉⠃⠛⠈|

2f. Auto:
🬙🬥🬪🬷🬥🬮🬛🬷🬁🬑🬦🬞🬗🬏🬗🬋🬠🬒🬕🬠🬓🬄🬶🬪🬵🬕🬺🬂🬒🬜🬁🬙
🬊🬛🬃🬉🬚🬒🬅🬥🬶🬢🬆🬮🬄🬃🬦🬪🬣🬕🬺🬴▌🬌🬋🬃🬠🬂🬵🬶🬋🬓█🬈

3a. Solids:
|█   █  ██  ██    █ ██ █   █ ██ █ █     ██  █ █ ██ █ █  ████   ██|
|███ ██ █  █   ██ █  ███     █ █ ███    ████ ██ ███ ███  ██      |
| █ █ █ █  █  ██ █ ███ █  █   █ █ █  ██ █  ████████    ██ ███   █|
|█ ██   █ ███    ██ █      ████ ██  █ ███ █    ███  ██  ████ ███ |
| ██   ██ ██  ██ █  ██  █       ██ ██ █ █ ██  █   ████ █ █  █  █ |
|█ █ ██ █ ███  ██ █ ███ █ █ █ █ ████   ██     █ ██ █   ███  █ ███|
| █   ████  █  ███ █ ██    ██ ██ ████ █   ██  █   █ ███ ██      █|
| █  █████████ █    █  █  ██ █ █      █     ███ █  █ █  █ █    █ |
|█ █ █ █ ████ ██  █ ███ █  ██      █     ████   ██  ████ ██  ██  |
| █ ████  █ ████ █ ██ ███  █  █ █  ████  █       █ ██    ███  ███|
| █  █    █ █  █ █  █    █         ███  █  █    █    █  █   █ ██ |
|█    █ █ ██    █ ███ ███ █   ██      █  ████ █ █  ██ ███ ███ █ █|

3b. Halves:
|█▄▄ █▄ █▀ ▄▀▀ ▄▄ █ ▀█▄█   ▀ █▀▄▀▄█▄    ██▄▄▀▄█ ██▄▀▄█▄ ▀██▀   ▀▀|
|▄▀▄█ ▀ █ ▄█▄ ▀▀ █▄▀█▀ ▀  ▀▄▄▄█ █▄▀ ▄▀█▄█ ▄▀▀▀▀███▀ ▄▄ ▀█▄██▀▄▄▄▀|
|▄▀█ ▄▄▀█ ██▄ ▀█▄▀▄ ██▄ █ ▄ ▄ ▄ ██▄█▀ ▀▄█ ▀▀  █ ▄▄▀█▀▀ █▄█  █ ▄█▄|
| █  ▄████▄▄█▄ █▀▀ ▀▄▀▀▄  ▄█▀▄▀█ ▀▀▀▀ █   ▀▀▄▄█ ▄ ▀▄▀█▀ █▀▄    ▄▀|
|▀▄▀▄█▄█ ▀█▀█▄██ ▄▀▄█▀█▄█  █▀ ▄ ▄  █▄▄▄  █▀▀▀   ▀█ ▄█▀▀▀ ██▄ ▀█▄▄|
|▄▀  ▀▄ ▄ █▄▀  ▀▄▀▄▄█ ▄▄▄▀▄   ▄▄   ▀▀▀▄ ▀▄▄█▄ ▄ █  ▄▄▀▄▄█ ▄▄█ █▀▄|

3c. Sextants:
|🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡|
|🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲|
|🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅|
|🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥|

3d. Octants:
|𜵞𜷏𜴤▐𜵱𜷁𜴙𜴔𜷅𜶞𜴕𜴍𜴘𜶬𜷒𜶔𜵟𜵴𜶜𜷕𜵽𜴭𜴵▟𜵮𜵹𜵂𜶞𜷚𜵢▂𜵔|
|𜶔▘𜷗𜷣𜷅𜷘𜴷𜵮𜴑𜶊𜴴𜴿𜵸𜵩𜵙▞𜴴𜴮𜶑𜴈𜴚𜶁𜷕𜵸𜴞𜵘𜵢𜶚𜶅▝𜴃𜵞|
|𜵚𜴄𜶍𜵵𜶘𜵜𜴈𜶅𜶆𜷙𜵻𜶹𜶀𜴂𜵸𜴽 𜴴𜶌𜴘𜶲𜶾𜺠𜶑▘𜶹𜶃𜷌𜵿𜷏𜶘𜶌|

3e. Braille:
|⡳⣢⠳⢸⢁⣎⠡⠖⣜⢬⠗⠇⠠⣁⣫⢪⡺⢂⢤⣸⢓⠮⠾⣼⡷⢑⡓⢬⣻⡥⣀⡩|
|⢪⠃⣲⣽⣜⣳⡈⡷⠕⢜⠷⡘⢐⡴⡰⡜⠷⠯⢨⠚⠨⢅⣸⢐⠪⡫⡥⢳⢇⠘⠐⡳|
|⡱⠑⢗⢃⢹⡹⠚⢇⢎⣺⢙⣚⢄⠋⢐⡐⠀⠷⢖⠠⣋⣍⢀⢨⠃⣚⢍⣡⢛⣢⢹⢖|

3f. Auto:
🬪🬢🬪▐🬀🬔🬟🬚🬘🬯🬛▌🬞🬀🬥🬤🬫🬃🬭▐🬌🬳🬻🬷🬺🬈🬌🬯🬬🬮 🬡
🬗🬕🬭🬫▐🬴🬇🬱🬥▐🬱🬦🬞🬡🬡▐🬲🬜🬉🬸🬉🬃🬦🬡🬗🬜🬄🬳🬕🬧🬡🬲
🬘🬏🬜🬝🬺🬻🬢🬕🬟🬧🬰🬢🬇🬴🬅🬄🬂🬒🬉 🬯🬶🬍🬦🬑🬤🬴🬘🬶 🬭🬅
🬘🬁🬥🬟▐🬘🬂🬣🬣🬸🬠🬰🬢🬀🬠🬑 🬎🬥🬇🬮🬱🬞🬦🬀🬰🬢🬵🬡🬶▐🬥

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// DefaultScaleWidth is the pixel width scale for bitmaps used as
	// [image.Image].
	DefaultScaleWidth uint = 24
	// DefaultScaleHeight is the pixel height scale for bitmaps used
	// as [image.Image].
	DefaultScaleHeight uint = 24
	// DefaultOpaque is the default opaque color.
	DefaultOpaque = color.Opaque
	// DefaultTransparent is the default transparent color.
	DefaultTransparent = color.Transparent
)

Functions

func ASCIIsRunes

func ASCIIsRunes() []rune

ASCIIsRunes returns the runes for double block resolution bitmaps.

func BinariesRunes

func BinariesRunes() []rune

BinariesRunes returns the runes for single block resolution bitmaps using '0', '1'.

func BrailleRunes

func BrailleRunes() []rune

BrailleRunes returns the runes for octuple block resolution images using braille.

See: https://www.amp-what.com/unicode/search/braille

func Dump

func Dump(w io.Writer, syms map[uint8]rune)

Dump dumps a ASCII drawing of the bitmask of the symbols to the writer.

Used to verify the symbols for different Type's.

func HalvesRunes

func HalvesRunes() []rune

HalvesRunes returns the runes for double block resolution bitmaps.

See: https://www.amp-what.com/unicode/search/half%20block

func OctantsRunes

func OctantsRunes() []rune

OctantsRunes returns the runes for octuple block resolution images.

See: https://www.amp-what.com/unicode/search/octants

func QuadsRunes

func QuadsRunes() []rune

QuadsRunes returns the runes for quadruple block resolution bitmaps.

See: https://www.amp-what.com/unicode/search/quarter%20block

func QuadsSeparatedRunes

func QuadsSeparatedRunes() []rune

QuadsSeparatedRunes returns the runes for quadruple block resolution images using separated quads.

See: https://www.amp-what.com/unicode/search/quad%20separated

func SextantsRunes

func SextantsRunes() []rune

SextantsRunes returns the runes for sextuple block resolution images.

See: https://www.amp-what.com/unicode/search/sextants

func SextantsSeparatedRunes

func SextantsSeparatedRunes() []rune

SextantsSeparatedRunes returns the runes for sextuple block resolution images using separated sextants.

See: https://www.amp-what.com/unicode/search/sextants%20separated

func SolidsRunes

func SolidsRunes() []rune

SolidsRunes returns the runes for single block resolution bitmaps.

See: https://www.amp-what.com/unicode/search/full%20block

func XXsRunes

func XXsRunes() []rune

XXsRunes returns the runes for single block resolution bitmaps using ' ', 'X'.

Types

type Bitmap

type Bitmap struct {
	Pix         []uint8
	Stride      int
	Rect        image.Rectangle
	ScaleWidth  uint
	ScaleHeight uint
	Opaque      color.Alpha16
	Transparent color.Alpha16
}

Bitmap is a monotone bitmap image.

func New

func New(data any, x int) (Bitmap, error)

New creates a new bitmap from data with width x. Data can be any type that works with binary.Write.

func NewBytes added in v0.2.0

func NewBytes(data []byte, x, y int) (Bitmap, error)

NewBytes creates a new bitmap from for the unaligned bytes in data with width x, height y.

func NewImage added in v0.2.0

func NewImage(rect image.Rectangle) Bitmap

NewImage creates a blank bitmap image with dimensions in rect.

func NewReader added in v0.2.0

func NewReader(r io.Reader, x int) (Bitmap, error)

NewReader creates a new bitmap from the reader with bit width x.

func (Bitmap) At

func (img Bitmap) At(x, y int) color.Color

At satisfies the image.Image interface.

func (Bitmap) Best added in v0.2.0

func (img Bitmap) Best() Type

Best returns the Best block type for the image.

func (Bitmap) Bounds

func (img Bitmap) Bounds() image.Rectangle

Bounds satisfies the image.Image interface.

func (Bitmap) Bytes added in v0.2.1

func (img Bitmap) Bytes() []byte

Bytes returns the bitmap encoded using the Bitmap.Best block type.

func (Bitmap) ColorModel

func (img Bitmap) ColorModel() color.Model

ColorModel satisfies the image.Image interface.

func (Bitmap) Encode

func (img Bitmap) Encode(w io.Writer, typ Type) error

Encode encodes the bitmap to the writer using the block type.

func (Bitmap) Format added in v0.1.4

func (img Bitmap) Format(f fmt.State, verb rune)

Format satisfies the fmt.Formatter interface.

func (Bitmap) Get

func (img Bitmap) Get(x, y int) bool

Get returns the bit at x, y.

func (Bitmap) Height

func (img Bitmap) Height(typ Type) int

Height returns the height for the block type.

func (Bitmap) Scale added in v0.2.0

func (img Bitmap) Scale() (int, int)

Scale returns the image width and height scale factors.

func (Bitmap) Set

func (img Bitmap) Set(x, y int, b bool)

Set sets the bit at x, y.

func (Bitmap) Width

func (img Bitmap) Width(typ Type) int

Width returns the width for the block type.

type Type

type Type rune

Type is a block type.

const (
	// Auto uses [Best] to determine the best, contiguous block type to use for
	// a provided height.
	Auto Type = 'v'
	// Solids are single, 1x1 blocks using [SolidsRunes].
	Solids Type = 'l'
	// Binaries are single, 1x1 blocks using binary digits using [BinariesRunes].
	Binaries Type = 'b'
	// XXs are single, 1x1 blocks using [XXsRunes].
	XXs Type = 'L'
	// Doubles are single, 0.5x1 double wide blocks using [SolidsRunes].
	Doubles Type = 'D'
	// Halves are 0.5x1 double wide blocks using [HalvesRunes].
	Halves Type = 'e'
	// Halves are 1x2 double height blocks using ASCII-safe runes using
	// [ASCIIsRunes].
	ASCIIs Type = 'E'
	// Quads are 3x2 quarter blocks using [QuadsRunes].
	Quads Type = 'q'
	// QuadsSeparated are 2x2 quarter blocks using [QuadsSeparatedRunes].
	QuadsSeparated Type = 'Q'
	// Sextants are 2x3 blocks using [SextantsRunes].
	Sextants Type = 'x'
	// SextantsSeparated are 2x3 blocks using [SextantsSeparatedRunes].
	SextantsSeparated Type = 'X'
	// Octants are 2x4 blocks using [OctantsRunes].
	Octants Type = 'o'
	// Braille are 2x4 blocks using [BrailleRunes].
	Braille Type = 'O'
)

Block types.

func Best

func Best(y int) Type

Best returns the best display block type for the height.

func Types

func Types() []Type

Types returns all block types.

func (Type) Contiguous

func (typ Type) Contiguous() bool

Contiguous returns true when the type is a contiguous block type.

func (Type) Dump

func (typ Type) Dump(w io.Writer)

Dump dumps a ASCII drawing of the bitmask the block type's symbols to the writer.

func (Type) Height

func (typ Type) Height() int

Height returns the height for the block type.

func (Type) Rune

func (typ Type) Rune() rune

Rune returns the verb rune for the type.

func (Type) RuneCount

func (typ Type) RuneCount() int

RuneCount returns the number of runes for the block type.

func (Type) RuneMap

func (typ Type) RuneMap() map[uint8]rune

RuneMap returns the rune map for the block type.

func (Type) Runes

func (typ Type) Runes() []rune

Runes returns the runes for the block type.

func (Type) String

func (typ Type) String() string

String satisfies the fmt.Stringer interface.

func (Type) ToRune

func (typ Type) ToRune(b uint8) rune

ToRune converts a byte to its block rune.

func (Type) Width

func (typ Type) Width() int

Width returns the width for the block type.

Jump to

Keyboard shortcuts

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