-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.go
49 lines (44 loc) · 1005 Bytes
/
text.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
package insta
import (
"fmt"
"image"
"io/ioutil"
"log"
"path"
"path/filepath"
"time"
"golang.org/x/image/font"
"golang.org/x/image/font/plan9font"
"golang.org/x/image/math/fixed"
)
func ScrollText(c Client, text string, speed time.Duration, base int) {
fontWidth := 10
fontHeight := 20
fontName := fmt.Sprintf("%dx%d", fontWidth, fontHeight)
readFile := func(name string) ([]byte, error) {
return ioutil.ReadFile(filepath.FromSlash(path.Join("plan9fonts/"+fontName, name)))
}
fontData, err := readFile(fontName + ".font")
if err != nil {
log.Fatal(err)
}
face, err := plan9font.ParseFont(fontData, readFile)
if err != nil {
log.Fatal(err)
}
steps := len(text)*fontWidth + ScreenWidth
fmt.Println(steps)
for i := 0; i < steps; i++ {
scr := NewScreen()
d := &font.Drawer{
Dst: scr,
Src: image.White,
Face: face,
Dot: fixed.P(-i+ScreenWidth, base),
}
d.DrawString(text)
c.SetScreen(scr)
time.Sleep(speed)
}
time.Sleep(100 * time.Millisecond)
}