Skip to content

Commit

Permalink
Some cleaning and additional save file for the printed terminal art's…
Browse files Browse the repository at this point in the history
… color code
  • Loading branch information
eleby committed Mar 1, 2021
1 parent 3a50c5d commit 478bcb8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
20 changes: 20 additions & 0 deletions main/console.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import (
"image"
"image/color/palette"
"image/draw"
"log"
"os"
"strconv"
)
Expand Down Expand Up @@ -30,3 +34,19 @@ func hasParam(param string) bool {
}
return false
}

func printInTerminal(img image.Image, pointMin image.Point, pointMax image.Point, jump int) {
bounds := img.Bounds()
changedImage := image.NewPaletted(bounds, palette.Plan9)
draw.Draw(changedImage, changedImage.Rect, img, bounds.Min, draw.Src)
printedText := "\n"
for y := pointMin.Y; y < pointMax.Y; y += jump {
for x := pointMin.X; x < pointMax.X; x += jump {
colorA := changedImage.ColorIndexAt(x, y)
printedText += "\033[48;5;" + strconv.Itoa(int(colorA)) + "m "
}
printedText += "\033[0;00m\n"
}
log.Print(printedText)
saveStr(printedText)
}
19 changes: 0 additions & 19 deletions main/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ package main
import (
"image"
"image/color"
"image/color/palette"
"image/draw"
"image/png"
"log"
"os"
"strconv"
)

const MaxCharsWidthTerminal = 60

func launchPixellisator(f *os.File, min int, count int, increase int) {
img, _, err := image.Decode(f)
if err != nil {
Expand Down Expand Up @@ -47,21 +43,6 @@ func launchPixellisator(f *os.File, min int, count int, increase int) {
}
}

func printInTerminal(img image.Image, pointMin image.Point, pointMax image.Point, jump int) {
bounds := img.Bounds()
changedImage := image.NewPaletted(bounds, palette.Plan9)
draw.Draw(changedImage, changedImage.Rect, img, bounds.Min, draw.Src)
printedLine := ""
for y := pointMin.Y; y < pointMax.Y; y += jump {
printedLine = ""
for x := pointMin.X; x < pointMax.X; x += jump {
colorA := changedImage.ColorIndexAt(x, y)
printedLine += "\033[48;5;" + strconv.Itoa(int(colorA)) + "m "
}
log.Print(printedLine + "\033[0;00m\n")
}
}

func repixellise(img image.Image, pointMin image.Point, pointMax image.Point, min int) image.Image {
result := image.NewRGBA(image.Rectangle{Min: pointMin, Max: pointMax})
for y := pointMin.Y; y < pointMax.Y; y += min {
Expand Down
10 changes: 10 additions & 0 deletions main/saves.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

const ResultName = "result"
const SaveName = "log"
const TerminalPrintName = "print.log"

func save(min int, count int, increase int) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
Expand All @@ -26,6 +27,15 @@ func save(min int, count int, increase int) {
f.Write([]byte(os.Args[1] + ";" + strconv.Itoa(min) + ";" + strconv.Itoa(count) + ";" + strconv.Itoa(increase)))
}

func saveStr(str string) {
f, err := os.Create(TerminalPrintName)
if err != nil {
log.Print("Cannot create print save file")
}
defer f.Close()
f.Write([]byte(str))
}

func readAndGetParams() (string, int, int, int) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
Expand Down

0 comments on commit 478bcb8

Please sign in to comment.