← Back to Realms

Realm

gno.land/r/moul/demo/gnoface/v0

Overview

Realm Path
gno.land/r/moul/demo/gnoface/v0
Exported Functions
2
State Entries
0
Source Files
2
Total Package Entries
3

Exported Functions

2 exported functions

State

No state entries detected.

Source Code

FILES
gnoface.gno
go
1package gnoface
2
3import (
4	"math/rand"
5	"strconv"
6	"strings"
7
8	"gno.land/p/moul/entropy/v0"
9	"gno.land/p/nt/ufmt/v0"
10)
11
12func Render(path string) string {
13	seed := uint64(entropy.New().Value())
14
15	path = strings.TrimSpace(path)
16	if path != "" {
17		s, err := strconv.Atoi(path)
18		if err != nil {
19			panic(err)
20		}
21		seed = uint64(s)
22	}
23
24	output := ufmt.Sprintf("Gnoface #%d\n", seed)
25	output += "```\n" + Draw(seed) + "```\n"
26	return output
27}
28
29func Draw(seed uint64) string {
30	var (
31		hairs = []string{
32			"     s",
33			"  .......",
34			"   s s s",
35			"   /\\ /\\",
36			"  |||||||",
37		}
38		headtop = []string{
39			" /-------\\",
40			" /~~~~~~~\\",
41			" /|||||||\\",
42			" ////////\\",
43			" |||||||||",
44			" /\\\\\\\\\\\\\\\\",
45		}
46		headspace = []string{
47			" |       |",
48		}
49		eyebrow = []string{
50			"~",
51			"*",
52			"_",
53			".",
54		}
55		ear = []string{
56			"o",
57			" ",
58			"D",
59			"O",
60			"<",
61			">",
62			".",
63			"|",
64			")",
65			"(",
66		}
67		eyesmiddle = []string{
68			"| o   o |",
69			"| o   _ |",
70			"| _   o |",
71			"| .   . |",
72			"| O   O |",
73			"| v   v |",
74			"| X   X |",
75			"| x   X |",
76			"| X   D |",
77			"| ~   ~ |",
78		}
79		nose = []string{
80			" |   o   |",
81			" |   O   |",
82			" |   V   |",
83			" |   L   |",
84			" |   C   |",
85			" |   ~   |",
86			" |  . .  |",
87			" |   .   |",
88		}
89		mouth = []string{
90			" |  __/  |",
91			" |  \\_/  |",
92			" |   .   |",
93			" |  ___  |",
94			" |  ~~~  |",
95			" |  ===  |",
96			" |  <=>  |",
97		}
98		headbottom = []string{
99			" \\-------/",
100			" \\~~~~~~~/",
101			" \\_______/",
102		}
103	)
104
105	r := rand.New(rand.NewPCG(seed, 0xdeadbeef))
106
107	return pick(r, hairs) + "\n" +
108		pick(r, headtop) + "\n" +
109		pick(r, headspace) + "\n" +
110		" | " + pick(r, eyebrow) + "   " + pick(r, eyebrow) + " |\n" +
111		pick(r, ear) + pick(r, eyesmiddle) + pick(r, ear) + "\n" +
112		pick(r, headspace) + "\n" +
113		pick(r, nose) + "\n" +
114		pick(r, headspace) + "\n" +
115		pick(r, mouth) + "\n" +
116		pick(r, headspace) + "\n" +
117		pick(r, headbottom) + "\n"
118}
119
120func pick(r *rand.Rand, slice []string) string {
121	return slice[r.IntN(len(slice))]
122}
123
124// based on https://github.com/moul/pipotron/blob/master/dict/ascii-face.yml
125

Raw Package Data

Raw JSON data