forked from RussellRollins/cursorpark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
130 lines (110 loc) · 2.91 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"strings"
"time"
)
/**
Generates a random Cursor Park, so that Cursors in your
document can feel safe and secure, while enjoying nature.
Cursor Park & Nature Preserve
🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳
🌳 🐇 🐢 🌳
🌳 🦃🌳
🌳 🦍 🌲 🐍 🌳
🌳 🐘 🌳
🌳 🌳
🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳🌳
**/
const (
tree = "🌳"
blank = " "
)
func main() {
if err := inner(); err != nil {
fmt.Printf("cursorpark: %s", err)
os.Exit(1)
}
}
var (
width, height int
critterFrequency float64
)
func inner() error {
// Set the size of the Cursor Park
flag.IntVar(&width, "width", 20, "the width of the cursor park")
flag.IntVar(&width, "w", 20, "the width of the cursor park (shorthand)")
flag.IntVar(&height, "height", 7, "the height of the cursor park")
flag.IntVar(&height, "h", 7, "the height of the cursor park (shorthand)")
// Prepare to randomly generate critters
rand.Seed(time.Now().UTC().UnixNano())
flag.Float64Var(&critterFrequency, "freq", 0.07, "how often a critter appears")
flag.Float64Var(&critterFrequency, "f", 0.07, "how often a critter appears (shorthand)")
flag.Parse()
// Generate the top and bottom tree row
top := strings.Repeat(tree, width)
bottom := top
// Based on the desired height, generate a row starting and
// ending with a tree, with either blank or a critter in each
// space.
rows := []string{}
for i := 0; i < (height - 2); i++ {
rows = append(rows, genRow(width, critterFrequency))
}
// Print our Cursor Park to the Terminal
fmt.Println("Cursor Park & Nature Preserve")
fmt.Println(top)
for _, r := range rows {
fmt.Println(r)
}
fmt.Println(bottom)
return nil
}
// genRow generates a row of width, bookended by 🌳 with a
// critter in each space with a probablity of critterFrequency.
// For example:
// `🌳 🐖 🐁 🌳`
func genRow(width int, critterFrequency float64) string {
critters := critters()
var str strings.Builder
str.WriteString(tree)
for i := 0; i < (width - 2); i++ {
r := rand.Float64()
space := blank
if critterFrequency > r {
space = critters[rand.Intn(len(critters))]
}
str.WriteString(space)
}
str.WriteString(tree)
return str.String()
}
// critters returns a slice of animals and plants. Note that some emoji
// are not the same width as others, but these all are the same width as
// 🌳 anything added to this function must be as well.
func critters() []string {
return []string{
"🐍",
"🐖",
"🌴",
"🐝",
"🐢",
"🐇",
"🐐",
"🐛",
"🦍",
"🐘",
"🌵",
"🌲",
"🦀",
"🐌",
"🦃",
"🐈",
"🐕",
"🐁",
"🐑",
}
}