Created
February 21, 2020 16:48
-
-
Save kevin-cantwell/5898a3926af0cd9f4cee95e3f7f5c858 to your computer and use it in GitHub Desktop.
boxboxbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"math/rand" | |
"os" | |
"golang.org/x/crypto/ssh/terminal" | |
) | |
var ( | |
chars = []rune{'╭', '╮', '╯', '╰', '│', '─'} | |
) | |
func main() { | |
var ( | |
width, height = 40, 40 | |
) | |
if terminal.IsTerminal(int(os.Stdout.Fd())) { | |
w, h, err := terminal.GetSize(int(os.Stdout.Fd())) | |
if err != nil { | |
panic(err) | |
} | |
width, height = w, h | |
} | |
flag.IntVar(&width, "width", width, "Width") | |
flag.IntVar(&height, "height", height, "Height") | |
flag.Parse() | |
height-- | |
table := make([][]rune, height) | |
for y := 0; y < height; y++ { | |
table[y] = make([]rune, width) | |
for x := 0; x < width; x++ { | |
var r rune | |
switch { | |
case y == 0 && x == 0: | |
r = chars[rand.Intn(6)] | |
case y == 0 && x > 0: | |
switch table[y][x-1] { | |
case '╭', '╰', '─': | |
r = []rune{'╯', '╮', '─'}[rand.Intn(3)] | |
case '╯', '╮', '│': | |
r = []rune{'╭', '╰', '│'}[rand.Intn(3)] | |
} | |
case y > 0 && x == 0: | |
switch table[y-1][x] { | |
case '╭', '╮', '│': | |
r = []rune{'╯', '╰', '│'}[rand.Intn(3)] | |
case '╯', '╰', '─': | |
r = []rune{'╭', '╮', '─'}[rand.Intn(3)] | |
} | |
default: | |
switch rand.Intn(2) { | |
case 0: | |
switch table[y-1][x] { | |
case '╭', '╮', '│': | |
r = []rune{'╯', '╰', '│'}[rand.Intn(3)] | |
case '╯', '╰', '─': | |
r = []rune{'╭', '╮', '─'}[rand.Intn(3)] | |
} | |
case 1: | |
switch table[y][x-1] { | |
case '╭', '╰', '─': | |
r = []rune{'╯', '╮', '─'}[rand.Intn(3)] | |
case '╯', '╮', '│': | |
r = []rune{'╭', '╰', '│'}[rand.Intn(3)] | |
} | |
} | |
} | |
table[y][x] = r | |
} | |
} | |
for _, row := range table { | |
fmt.Println(string(row)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment