-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpony.go
50 lines (48 loc) · 975 Bytes
/
pony.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
package pony
import "strconv"
// Text makes phrase colorful. Offset adjusts the rainbow effect.
func Text(phrase string, offset int) string {
var parts [][]byte
appendc := func(x int) {
var p []byte
p = strconv.AppendInt(append(p, "\x1B[38;5;"...), int64(x), 10)
p = append(append(p, 'm', ' '), "\x1B[0m"...)
parts = append(parts, p)
}
x := 196
for i := 0; i < 2; i++ {
for j := 0; j < 7; j++ {
for k := 0; k < 2; k++ {
for l := 0; l < 6; l++ {
if l > 0 {
if k == 0 {
if i == 0 {
x = x - 36 + 1
} else {
x = x - 36
}
} else {
if i == 0 {
x = x + 36
} else {
x = x - 1 + 36
}
}
}
appendc(x)
}
}
}
}
var s []byte
for i := 0; i < len(parts) && i < len(phrase); i++ {
j := (i + offset) % len(parts)
if j < 0 {
j += len(parts)
}
p := parts[j]
p[len(p)-5] = phrase[i%len(phrase)]
s = append(s, p...)
}
return string(s)
}