Advertisement
mjunolainen

ascii-art1

Oct 19th, 2021
1,010
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.92 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "log"
  6.     "os"
  7.     "strings"
  8. )
  9.  
  10. func main() {
  11.     if len(os.Args) != 2 {
  12.         log.Fatal("Wrong number of arguments. Correct use: 'go run main.go <your input>'")
  13.     }
  14.     if os.Args[1] == "" {
  15.         return
  16.     }
  17.     // Create an array of lines from ascii art input file
  18.     fileBytes, err := os.ReadFile("standard.txt")
  19.     if err != nil {
  20.         log.Fatal(err)
  21.     }
  22.     fileString := string(fileBytes)
  23.     artArray := strings.Split(fileString, "\n")
  24.  
  25.     // Take written input from terminal and cut it into an array at "\n"
  26.     inputArray := strings.Split(os.Args[1], "\\n")
  27.  
  28.     // Print lines from artArray based on input string
  29.     for i := range inputArray {
  30.         if inputArray[i] == "" {
  31.             fmt.Println()
  32.         } else {
  33.             for charLine := 0; charLine < 8; charLine++ { // all ascii characters are 8 lines high
  34.                 for j := range inputArray[i] {
  35.                     pos := 1 + (int(inputArray[i][j])-32)*9 + charLine
  36.                     fmt.Print(artArray[pos])
  37.                 }
  38.                 fmt.Println()
  39.             }
  40.         }
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement