dancefloor-monorepo/go/patterns/character.go
2020-05-03 23:44:38 +01:00

304 lines
7.0 KiB
Go

package patterns
// character maps referenced [y][x]
var masks = make(map[rune]*[5][]bool)
type Character struct {
Character rune
Colour Colour
Background Colour
initiated bool
drawn [][]Colour
}
func (s *Character) Draw(width, height int) *[][]Colour {
if !s.initiated {
s.init(width, height)
s.initiated = true
}
return &s.drawn
}
func (s *Character) init(width, height int) {
if width == 0 {
if _, ok := masks[s.Character]; ok {
width = len(masks[s.Character][0])
}
}
s.drawn = make([][]Colour, width)
for i := 0; i < width; i++ {
s.drawn[i] = make([]Colour, height)
for j := 0; j < height; j++ {
s.drawn[i][j] = s.Background
if val, ok := masks[s.Character]; ok {
y := 5 - j - 1
if i < len(val[y]) && val[y][i] {
s.drawn[i][j] = s.Colour
}
}
}
}
}
func init() {
masks['a'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, true},
{true, true, true, true, true},
{true, false, false, false, true},
{true, false, false, false, true},
}
masks['A'] = masks['a']
masks['b'] = &[5][]bool{
{true, true, true, true, false},
{true, false, false, false, true},
{true, true, true, true, true},
{true, false, false, false, true},
{true, true, true, true, false},
}
masks['B'] = masks['b']
masks['c'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, false},
{true, false, false, false, false},
{true, false, false, false, false},
{true, true, true, true, true},
}
masks['C'] = masks['c']
masks['d'] = &[5][]bool{
{true, true, true, true, false},
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, true, true, true, false},
}
masks['D'] = masks['d']
masks['e'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, false},
{true, true, true, true, false},
{true, false, false, false, false},
{true, true, true, true, true},
}
masks['E'] = masks['e']
masks['f'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, false},
{true, true, true, true, false},
{true, false, false, false, false},
{true, false, false, false, false},
}
masks['F'] = masks['f']
masks['g'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, false},
{true, false, true, true, true},
{true, false, false, false, true},
{true, true, true, true, true},
}
masks['G'] = masks['g']
masks['h'] = &[5][]bool{
{true, false, false, false, true},
{true, false, false, false, true},
{true, true, true, true, true},
{true, false, false, false, true},
{true, false, false, false, true},
}
masks['H'] = masks['h']
masks['i'] = &[5][]bool{
{true, true, true, true, true},
{false, false, true, false, false},
{false, false, true, false, false},
{false, false, true, false, false},
{true, true, true, true, true},
}
masks['I'] = masks['i']
masks['j'] = &[5][]bool{
{true, true, true, true},
{false, false, true, false},
{false, false, true, false},
{true, false, true, false},
{true, true, true, false},
}
masks['J'] = masks['j']
masks['k'] = &[5][]bool{
{true, false, false, true},
{true, false, true, false},
{true, true, false, false},
{true, false, true, false},
{true, false, false, true},
}
masks['K'] = masks['k']
masks['l'] = &[5][]bool{
{true, false, false, false, false},
{true, false, false, false, false},
{true, false, false, false, false},
{true, false, false, false, false},
{true, true, true, true, true},
}
masks['L'] = masks['l']
masks['m'] = &[5][]bool{
{true, false, false, false, true},
{true, true, false, true, true},
{true, false, true, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
}
masks['M'] = masks['m']
masks['n'] = &[5][]bool{
{true, false, false, false, true},
{true, true, false, false, true},
{true, false, true, false, true},
{true, false, false, true, true},
{true, false, false, false, true},
}
masks['N'] = masks['n']
masks['o'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, true, true, true, true},
}
masks['O'] = masks['o']
masks['p'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, true},
{true, true, true, true, true},
{true, false, false, false, false},
{true, false, false, false, false},
}
masks['P'] = masks['p']
masks['q'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, true, true},
{true, true, true, true, true},
}
masks['Q'] = masks['q']
masks['r'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, true},
{true, true, true, true, true},
{true, false, false, true, false},
{true, false, false, false, true},
}
masks['R'] = masks['r']
masks['s'] = &[5][]bool{
{true, true, true, true, true},
{true, false, false, false, false},
{true, true, true, true, true},
{false, false, false, false, true},
{true, true, true, true, true},
}
masks['S'] = masks['s']
masks['t'] = &[5][]bool{
{true, true, true, true, true},
{false, false, true, false, false},
{false, false, true, false, false},
{false, false, true, false, false},
{false, false, true, false, false},
}
masks['T'] = masks['t']
masks['u'] = &[5][]bool{
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, true, true, true, true},
}
masks['U'] = masks['u']
masks['v'] = &[5][]bool{
{true, false, false, false, true},
{true, false, false, false, true},
{false, true, false, true, false},
{false, true, false, true, false},
{false, false, true, false, false},
}
masks['V'] = masks['v']
masks['w'] = &[5][]bool{
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, false, false, true},
{true, false, true, false, true},
{true, true, false, true, true},
}
masks['W'] = masks['w']
masks['x'] = &[5][]bool{
{true, false, false, false, true},
{false, true, false, true, false},
{false, false, true, false, false},
{false, true, false, true, false},
{true, false, false, false, true},
}
masks['X'] = masks['x']
masks['y'] = &[5][]bool{
{true, false, false, false, true},
{false, true, false, true, false},
{false, false, true, false, false},
{false, false, true, false, false},
{false, false, true, false, false},
}
masks['Y'] = masks['y']
masks['z'] = &[5][]bool{
{true, true, true, true, true},
{false, false, false, true, false},
{false, false, true, false, false},
{false, true, false, false, false},
{true, true, true, true, true},
}
masks['Z'] = masks['z']
masks[' '] = &[5][]bool{
{false},
{false},
{false},
{false},
{false},
}
masks['.'] = &[5][]bool{
{false},
{false},
{false},
{false},
{true},
}
masks['!'] = &[5][]bool{
{true},
{true},
{true},
{false},
{true},
}
}