added colors

This commit is contained in:
Lorenz Hohermuth 2024-02-15 15:20:13 +01:00
parent c70b369f31
commit dc6ec67168
2 changed files with 51 additions and 22 deletions

View File

@ -1,30 +1,52 @@
package color
import "fmt"
import (
"fmt"
"math"
)
var colorForeground = map[[3]int]string {
[3]int{0, 0, 0}:"\033[30m",
[3]int{204, 0, 0}:"\033[31m",
[3]int{78, 154, 6}:"\033[32m",
[3]int{196, 160, 0}:"\033[33m",
[3]int{114, 159, 207}:"\033[34m",
[3]int{117, 80, 123}:"\033[35m",
[3]int{6, 152, 154}:"\033[36m",
[3]int{211, 215, 207}:"\033[37m",
[3]int{85, 87, 83}:"\033[90m",
[3]int{239, 41, 41}:"\033[91m",
[3]int{138, 226, 52}:"\033[92m",
[3]int{252, 233, 79}:"\033[93m",
[3]int{50, 175, 255}:"\033[94m",
[3]int{173, 127, 168}:"\033[95m",
[3]int{52, 226, 226}:"\033[96m",
[3]int{255, 255, 255}:"\033[97m",
[3]int{0, 0, 0}:"\033[30m", //black
[3]int{204, 0, 0}:"\033[31m", //dark red
[3]int{25, 203, 0}:"\033[32m", //dark green
[3]int{206, 203, 0}:"\033[33m", //dark yellow
[3]int{13, 115, 204}:"\033[34m", //dark blue
[3]int{203, 20, 209}:"\033[35m", //dark pink
[3]int{13, 205, 205}:"\033[36m", //dark cyan
[3]int{221, 221, 221}:"\033[37m", //dark white
[3]int{118, 118, 118}:"\033[90m", // grey
[3]int{242, 32, 31}:"\033[91m", //red
[3]int{35, 253, 0}:"\033[92m", //green
[3]int{255, 253, 0}:"\033[93m", //yellow
[3]int{26, 143, 255}:"\033[94m", //blue
[3]int{253, 40, 255}:"\033[95m", //pink
[3]int{20, 255, 255}:"\033[96m", // cyan
[3]int{255, 255, 255}:"\033[97m", //white
}
func PrintColorPallet() {
non := "\033[0m"
arr := []string{"\033[49m", "\033[40m", "\033[41m", "\033[42m", "\033[43m", "\033[44m", "\033[45m", "\033[46m", "\033[47m", "\033[100m", "\033[101m", "\033[102m", "\033[103m", "\033[104m", "\033[105m", "\033[106m", "\033[107m"}
for _, v := range arr {
fmt.Println(v, " ", non)
arr := []string{"\033[40m", "\033[41m", "\033[42m", "\033[43m", "\033[44m", "\033[45m", "\033[46m", "\033[47m", "\033[100m", "\033[101m", "\033[102m", "\033[103m", "\033[104m", "\033[105m", "\033[106m", "\033[107m"}
for i, v := range arr {
fmt.Println(i, v, " ", non)
}
}
func GetColor(p [3]int) (string, string) {
var color string = "\033[39m"
var delta float64 = 255
r2 := float64(p[0])
g2 := float64(p[1])
b2 := float64(p[2])
for k, v := range colorForeground {
r1 := float64(k[0])
g1 := float64(k[1])
b1 := float64(k[2])
otherDelta := math.Sqrt(math.Pow((r2-r1)*0.6, 2) + math.Pow((g2-g1)*1.5, 2) + math.Pow((b2-b1)*0.5,2))
if (otherDelta < delta) {
delta = otherDelta
color = v
}
}
return color, "\033[0m"
}

11
main.go
View File

@ -4,6 +4,8 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package main
import (
"fmt"
"github.com/LorenzHohermuth/cli-shapes/cmd"
"github.com/LorenzHohermuth/cli-shapes/internal/color"
"github.com/LorenzHohermuth/cli-shapes/internal/renderer"
@ -11,14 +13,19 @@ import (
)
func main() {
pix := image.ImageToPixles("/home/lorenz/Downloads/crab.png")
//pix := image.ImageToPixles("/home/lorenz/Downloads/mushroom-mini.png")
//pix := image.ImageToPixles("/home/lorenz/Downloads/rgb.png")
pix := image.ImageToPixles("/home/lorenz/Downloads/yoshi.png")
s := ""
for _, y := range pix {
for _, x := range y {
s += renderer.GetChar(x.Brightness())
color, non := color.GetColor([3]int{x.R, x.G, x.B})
char := renderer.GetChar(x.Brightness())
s += color + char + non
}
s += "\n"
}
fmt.Println(s)
color.PrintColorPallet()
cmd.Execute()
}