-
Notifications
You must be signed in to change notification settings - Fork 4
/
printer.go
128 lines (116 loc) · 2.4 KB
/
printer.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
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strconv"
"strings"
"time"
)
var (
// notes
fullnote int = 1678
halfnote int = 839
quaternote int = 420
eightnote int = 210
sixteenthnote int = 105
thirtysecondnote int = 52
sixtyfourthnote int = 26
)
type Sized struct {
width int
height int
}
func printer(done chan bool) {
s := &Sized{}
s.width, s.height = checkTerminalSize()
// intro
intro()
// verse 1
verse1()
// chorus 1
chorusBig1()
chorusBig1()
overAndOver()
chorusBig1()
// verse 2
verse2()
// chorus 2 - ends faster and starts loading bar
chorusBig1()
chorusBig1()
overAndOver()
chorusSmall1()
// solo
s.solo()
// chorus 3 - can't feel, can see...
s.lastChorus()
<-done
}
func (s *Sized) printNoteInBinary(note string, speed int) {
var toBinary string
for _, c := range note {
toBinary += fmt.Sprintf("%b ", c)
}
freq := (float64(speed) / float64(len(toBinary))) // to microseconds
for _, b := range toBinary {
fmt.Printf("%c", b)
time.Sleep(time.Millisecond * time.Duration(freq))
}
fmt.Println()
}
func printInMicroseconds(s string, spd int) {
speed := spd * 1000
freq := (float64(speed) / float64(len(s)))
for i := 0; i < len(s); i++ {
fmt.Printf("%v", string(s[i]))
time.Sleep(time.Microsecond * time.Duration(freq))
}
}
func printBinaryInMicroseconds(s string, spd int) {
speed := spd * 1000
var toBinary string
for _, c := range s {
toBinary += fmt.Sprintf("%b ", c)
}
freq := (float64(speed) / float64(len(toBinary))) // to microseconds
for _, b := range toBinary {
fmt.Printf("%c", b)
time.Sleep(time.Microsecond * time.Duration(freq))
}
fmt.Println()
}
func cleanDisplay() {
fmt.Printf("\x1b[2J")
moveCursor(0, 0)
}
func moveCursor(row, col int) {
fmt.Printf("\x1b[%d;%df", row+1, col+1)
}
func centerText(s string, w int) string {
return fmt.Sprintf("%[1]*s", -w, fmt.Sprintf("%[1]*s", (w+len(s))/2, s))
}
func noteRest(note int) {
time.Sleep(time.Millisecond * time.Duration(note))
}
func checkTerminalSize() (int, int) {
cmd := exec.Command("stty", "size")
cmd.Stdin = os.Stdin
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
return 0, 0
}
valuePairs := strings.Fields(string(out))
height, err := strconv.Atoi(valuePairs[0])
if err != nil {
log.Fatal(err)
return 0, 0
}
width, err := strconv.Atoi(valuePairs[1])
if err != nil {
log.Fatal(err)
return 0, 0
}
return width, height
}