mjunolainen

ascii-art3

Oct 19th, 2021
773
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
  22.                 //fmt.Print(finalString)
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. func characterReader(lause string, i int) string { // function to find row index, join that row for every char and return it
  29.     var line string
  30.     var finalLine string
  31.  
  32.     for j := 0; j < len(lause); j++ { // looping a row of every char in lause
  33.         char := lause[j]
  34.         index := 2 + (9 * (int(char) - 32)) + i // finding starting row
  35.  
  36.         file, err := os.Open("standard.txt")
  37.         if err != nil {
  38.             panic(err)
  39.         }
  40.  
  41.         reader := bufio.NewReader(file)
  42.         // loop font file to find right row to print
  43.         for firstLine := 1; firstLine <= index; firstLine++ {
  44.             line, err = reader.ReadString('\n')
  45.             if err != nil {
  46.                 break
  47.             }
  48.             if firstLine == index { // adding lines together
  49.                 if j == len(lause)-1 { // keeping \n if its a last char in lause
  50.                     finalLine = finalLine + line
  51.                 } else { // removing newlines to keep row in one line
  52.                     finalLine = finalLine + strings.TrimRight(line, "\n")
  53.                 }
  54.             }
  55.         }
  56.         file.Close()
  57.     }
  58.     return finalLine
  59. }
  60.  
RAW Paste Data