Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Playground

gnoface.gno

package gnoface

import (
	"math/rand"
	"strconv"
	"strings"

	"gno.land/p/moul/entropy/v0"
	"gno.land/p/nt/ufmt/v0"
)

func Render(path string) string {
	seed := uint64(entropy.New().Value())

	path = strings.TrimSpace(path)
	if path != "" {
		s, err := strconv.Atoi(path)
		if err != nil {
			panic(err)
		}
		seed = uint64(s)
	}

	output := ufmt.Sprintf("Gnoface #%d\n", seed)
	output += "```\n" + Draw(seed) + "```\n"
	return output
}

func Draw(seed uint64) string {
	var (
		hairs = []string{
			"     s",
			"  .......",
			"   s s s",
			"   /\\ /\\",
			"  |||||||",
		}
		headtop = []string{
			" /-------\\",
			" /~~~~~~~\\",
			" /|||||||\\",
			" ////////\\",
			" |||||||||",
			" /\\\\\\\\\\\\\\\\",
		}
		headspace = []string{
			" |       |",
		}
		eyebrow = []string{
			"~",
			"*",
			"_",
			".",
		}
		ear = []string{
			"o",
			" ",
			"D",
			"O",
			"<",
			">",
			".",
			"|",
			")",
			"(",
		}
		eyesmiddle = []string{
			"| o   o |",
			"| o   _ |",
			"| _   o |",
			"| .   . |",
			"| O   O |",
			"| v   v |",
			"| X   X |",
			"| x   X |",
			"| X   D |",
			"| ~   ~ |",
		}
		nose = []string{
			" |   o   |",
			" |   O   |",
			" |   V   |",
			" |   L   |",
			" |   C   |",
			" |   ~   |",
			" |  . .  |",
			" |   .   |",
		}
		mouth = []string{
			" |  __/  |",
			" |  \\_/  |",
			" |   .   |",
			" |  ___  |",
			" |  ~~~  |",
			" |  ===  |",
			" |  <=>  |",
		}
		headbottom = []string{
			" \\-------/",
			" \\~~~~~~~/",
			" \\_______/",
		}
	)

	r := rand.New(rand.NewPCG(seed, 0xdeadbeef))

	return pick(r, hairs) + "\n" +
		pick(r, headtop) + "\n" +
		pick(r, headspace) + "\n" +
		" | " + pick(r, eyebrow) + "   " + pick(r, eyebrow) + " |\n" +
		pick(r, ear) + pick(r, eyesmiddle) + pick(r, ear) + "\n" +
		pick(r, headspace) + "\n" +
		pick(r, nose) + "\n" +
		pick(r, headspace) + "\n" +
		pick(r, mouth) + "\n" +
		pick(r, headspace) + "\n" +
		pick(r, headbottom) + "\n"
}

func pick(r *rand.Rand, slice []string) string {
	return slice[r.IntN(len(slice))]
}

// based on https://github.com/moul/pipotron/blob/master/dict/ascii-face.yml

gnomod.toml

module = "gno.land/r/moul/demo/gnoface/v0"
gno = "0.9"

[addpkg]
  creator = "g1manfred47kzduec920z88wfr64ylksmdcedlf5"
  height = 26336
  max_deposit = "100000000ugnot"