view src/gomatrix.go @ 35:a4a54931b6fa

add gf.go.
author pyon@macmini
date Wed, 20 Nov 2019 06:19:13 +0900
parents 1b293bb0a011
children
line wrap: on
line source

package main

import (
	"flag"
	"fmt"
	"math/rand"
	"runtime"
	"time"
)

func main() {
	sw := flag.Int( "w",  40, "screen width" )
	sl := flag.Int( "s", 100, "interval" )
	flag.Parse()

	s := "0123456789abcdefghijkemnopqrstuvwxyzABCDEFGHIJKEMNOPQRSTUVWXYZ!@#$%&*|;:.,=+-/"
	n := len( s )
	r := 0
	for i := 1 ; ; i++ {
		r = rand.Intn( n )
		fmt.Printf( "%s ", random_color( s[r] ) )
		if i == *sw {
			for t := 0; t < *sl; t++ {
				time.Sleep( time.Millisecond )
			}
			fmt.Println()
			i = 0
		}
	}
}

func random_color( s byte ) string {
	if runtime.GOOS == "windows" {
		return string( s )
	}
	// black, red, green yellow, blue, magenta, cyan, white
	c := [...]int{ 30, 31, 32, 33, 34, 35, 36, 37 }
	r := rand.Intn( len( c ) )
	return fmt.Sprintf( "\x1b[%dm%c\x1b[0m", c[r], s )
}