github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/r/demo/art/millipede/millipede.gno (about)

     1  package millipede
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  
     7  	"gno.land/p/demo/ufmt"
     8  )
     9  
    10  const (
    11  	minSize     = 1
    12  	defaultSize = 20
    13  	maxSize     = 100
    14  )
    15  
    16  func 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  
    29  func 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/art/millpede:%d)< ", size-1, size-1)
    44  	}
    45  	if size < maxSize {
    46  		output += ufmt.Sprintf(" >[%d](/r/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