1package millipede
2
3import (
4 "strconv"
5 "strings"
6
7 "gno.land/p/demo/ufmt"
8)
9
10const (
11 minSize = 1
12 defaultSize = 20
13 maxSize = 100
14)
15
16func Draw(size int) string {
17 if size < minSize || size > maxSize {
18 panic("invalid millipede size")
19 }
20 paddings := []string{" ", " ", "", " ", " ", " ", " ", " ", " "}
21 var b strings.Builder
22 b.WriteString(" ╚⊙ ⊙╝\n")
23 for i := 0; i < size; i++ {
24 b.WriteString(paddings[i%9] + "╚═(███)═╝\n")
25 }
26 return b.String()
27}
28
29func Render(path string) string {
30 size := defaultSize
31
32 path = strings.TrimSpace(path)
33 if path != "" {
34 var err error
35 size, err = strconv.Atoi(path)
36 if err != nil {
37 panic(err)
38 }
39 }
40
41 output := "```\n" + Draw(size) + "```\n"
42 if size > minSize {
43 output += ufmt.Sprintf("[%d](/r/demo/art/millipede:%d)< ", size-1, size-1)
44 }
45 if size < maxSize {
46 output += ufmt.Sprintf(" >[%d](/r/demo/art/millipede:%d)", size+1, size+1)
47 }
48 return output
49}
50
51// based on https://github.com/getmillipede/millipede-go/blob/977f046c39c35a650eac0fd30245e96b22c7803c/main.go
millipede.gno
1.04 Kb · 51 lines