Browse Source

The second version we refactored together with Olari

master
Robert Reimann 3 years ago
parent
commit
da1c412091
  1. 49
      main.go

49
main.go

@ -1,54 +1,23 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
// If we have any other number of parameters, than one
if len(os.Args[1:]) != 1 {
return
}
// Separate every line
lines := strings.Split(string(os.Args[1]), "\\n")
// The most stupid fix in the world, for the empty lines
// This variable stores how many new lines we add to the very end
newLineCount := 0
// Just remove the new lines from the very end... splitting at \n causes empty strings to occur in the slice
for lines[len(lines)-1] == "" {
lines = lines[:len(lines)-1]
newLineCount++
}
// Read in the alphabet
alphabet, err := ioutil.ReadFile("standard.txt")
if err != nil {
return
for ; lines[len(lines)-1] == ""; lines = lines[:len(lines)-1] {
defer os.Stdout.WriteString("\n")
}
alpha := strings.Split(string(alphabet), "\n")
// Loop through the slice of lines
for _, v := range lines {
// Loop through the lines of the font
// All the characters are made up of eight lines
// Essentially, 'i' tells us which line of printing we are at
for i := 0; i < 8; i++ {
// Loop through the current line
for _, w := range v {
// Get the index of the character in the font file
fmt.Print(alpha[(w-32)*9+rune(i+1)])
bytes, _ := os.ReadFile("standard.txt")
alphabet := strings.Split(string(bytes), "\n")
for _, line := range lines {
for i := 1; i < 9; i++ {
for _, char := range line {
os.Stdout.WriteString(alphabet[(char-32)*9+rune(i)])
}
// Print out a new line for the future parts of the characters
fmt.Println()
os.Stdout.WriteString("\n")
}
}
// Add the newLines to the very end of the printing
for ; newLineCount > 0; newLineCount-- {
fmt.Println()
}
}

Loading…
Cancel
Save