-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnow.go
62 lines (47 loc) · 937 Bytes
/
snow.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
package main
import (
"math/rand"
"time"
"github.com/inancgumus/screen"
)
type snow struct {
speed int
stack bool
particle rune
colour string
}
func (s *snow) show() {
screen.Clear()
term := getTerminalAttr()
currentRows := make(map[int]int)
snowflakes := make(map[int]*row)
for {
targetColumn := rand.Intn(term.columns)
if targetColumn%2 == 0 {
continue
}
if _, onScreen := snowflakes[targetColumn]; onScreen {
moveFlake(snowflakes,
currentRows,
targetColumn,
s.stack,
s.colour,
term,
s.particle)
} else {
flake := getFlake(s.particle)
snowflakes[targetColumn] = &row{0, flake}
printSnowflakeCol(snowflakes, targetColumn, s.colour)
}
for existingFlake := range snowflakes {
moveFlake(snowflakes,
currentRows,
existingFlake,
s.stack,
s.colour,
term,
s.particle)
}
time.Sleep(time.Second / time.Duration(s.speed))
}
}