Advertisement
mjunolainen

ascii-art

Oct 4th, 2021
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.54 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "bufio"
  5.     "fmt"
  6.     "os"
  7.     "strings"
  8. )
  9.  
  10. func main() {
  11.     inputString := os.Args[1]                         // string
  12.     finalString := ""                                 // to be printed out line-by-line
  13.     slicedString := strings.Split(inputString, "\\n") // slicing words to handle \n
  14.  
  15.     for j, words := range slicedString { // going through every word in slice
  16.         if words == "" && j != 0 {
  17.             fmt.Println()
  18.         } else if words != "" {
  19.             for i := 0; i < 8; i++ { // printing out 8 lines
  20.                 finalString = characterReader(words, i) // returns one row that includes first line of every char
  21.                 fmt.Print(finalString)
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27. func characterReader(lause string, i int) string { // function to find row index, join that row for every char and return it
  28.     var line string
  29.     var finalLine string
  30.  
  31.     for j := 0; j < len(lause); j++ { // looping a row of every char in lause
  32.         char := lause[j]
  33.         index := 2 + (9 * (int(char) - 32)) + i // finding starting row
  34.  
  35.         file, err := os.Open("standard.txt")
  36.         if err != nil {
  37.             panic(err)
  38.         }
  39.  
  40.         reader := bufio.NewReader(file)
  41.         // loop font file to find right row to print
  42.         for firstLine := 1; firstLine <= index; firstLine++ {
  43.             line, err = reader.ReadString('\n')
  44.             if err != nil {
  45.                 break
  46.             }
  47.             if firstLine == index { // adding lines together
  48.                 if j == len(lause)-1 { // keeping \n if its a last char in lause
  49.                     finalLine = finalLine + line
  50.                 } else { // removing newlines to keep row in one line
  51.                     finalLine = finalLine + strings.TrimRight(line, "\n")
  52.                 }
  53.             }
  54.         }
  55.         file.Close()
  56.     }
  57.     return finalLine
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement