26
|
1 package main
|
|
2
|
|
3 import (
|
|
4 "flag"
|
|
5 "fmt"
|
|
6 "math/rand"
|
|
7 "runtime"
|
|
8 "time"
|
|
9 )
|
|
10
|
|
11 func main() {
|
|
12 sw := flag.Int( "w", 40, "screen width" )
|
|
13 sl := flag.Int( "s", 100, "interval" )
|
|
14 flag.Parse()
|
|
15
|
|
16 s := "0123456789abcdefghijkemnopqrstuvwxyzABCDEFGHIJKEMNOPQRSTUVWXYZ!@#$%&*|;:.,=+-/"
|
|
17 n := len( s )
|
|
18 r := 0
|
|
19 for i := 1 ; ; i++ {
|
|
20 r = rand.Intn( n )
|
|
21 fmt.Printf( "%s ", random_color( s[r] ) )
|
|
22 if i == *sw {
|
|
23 for t := 0; t < *sl; t++ {
|
|
24 time.Sleep( time.Millisecond )
|
|
25 }
|
|
26 fmt.Println()
|
|
27 i = 0
|
|
28 }
|
|
29 }
|
|
30 }
|
|
31
|
|
32 func random_color( s byte ) string {
|
|
33 if runtime.GOOS == "windows" {
|
|
34 return string( s )
|
|
35 }
|
|
36 // black, red, green yellow, blue, magenta, cyan, white
|
|
37 c := [...]int{ 30, 31, 32, 33, 34, 35, 36, 37 }
|
|
38 r := rand.Intn( len( c ) )
|
|
39 return fmt.Sprintf( "\x1b[%dm%c\x1b[0m", c[r], s )
|
|
40 }
|
|
41
|