cycle throw nerdfont icons

This commit is contained in:
Lorenz Hohermuth 2024-02-26 12:54:59 +01:00
parent 3bf398fcad
commit ab9eb8e798
12 changed files with 9403 additions and 9337 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tmp/

47
cmd/calibrate.go Normal file
View File

@ -0,0 +1,47 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd
import (
"fmt"
"github.com/LorenzHohermuth/cli-shapes/internal/nerdfont"
"github.com/LorenzHohermuth/cli-shapes/pkg/canvas"
"github.com/LorenzHohermuth/cli-shapes/pkg/image"
"github.com/spf13/cobra"
)
// calibrateCmd represents the calibrate command
var calibrateCmd = &cobra.Command{
Use: "calibrate",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
icons := nerdfont.ParseFile("./nerd-font-icons")
for i, v := range icons {
fmt.Printf("%g %% %s\n", (float64(i) + 1) / float64(len(icons)) * 100, v)
path := canvas.CharacterAnalyse(v)
image.ImageToPixles(path)
}
},
}
func init() {
rootCmd.AddCommand(calibrateCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// calibrateCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// calibrateCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -0,0 +1,20 @@
package nerdfont
import (
"os"
"strings"
)
func ParseFile(pathToFile string) []string {
dat, err := os.ReadFile(pathToFile)
check(err)
text := strings.Replace(string(dat), "\n", "", -1)
lines := strings.Split(text, ",")
return lines
}
func check(err error) {
if err != nil {
panic(err)
}
}

View File

@ -111,4 +111,3 @@ func GetChar(brightness float64) string {
} }
return char return char
} }

View File

@ -5,10 +5,10 @@ package main
import ( import (
"github.com/LorenzHohermuth/cli-shapes/cmd" "github.com/LorenzHohermuth/cli-shapes/cmd"
//"github.com/LorenzHohermuth/cli-shapes/pkg/canvas" "github.com/LorenzHohermuth/cli-shapes/pkg/canvas"
) )
func main() { func main() {
//canvas.CharacterAnalyse("󰎖") canvas.CharacterAnalyse("")
cmd.Execute() cmd.Execute()
} }

9327
nerd-font-icons Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
package canvas package canvas
import ( import (
"fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -10,10 +9,10 @@ import (
) )
func CharacterAnalyse(character string) string{ func CharacterAnalyse(character string) string{
const fontSize = 40.0 const fontSize = 30.0
const hFontToPixelRatio = 0.3 const hFontToPixelRatio = 0.3
const wFontToPixelRatio = 0.225 const wFontToPixelRatio = 0.225
fileName := fmt.Sprintf("tmp/nf-icon-%s.png" , character) fileName := "tmp/nf-icon-nf.png"
// Create new canvas of dimension 100x100 mm // Create new canvas of dimension 100x100 mm
c := canvas.New(fontSize * wFontToPixelRatio, fontSize * hFontToPixelRatio) c := canvas.New(fontSize * wFontToPixelRatio, fontSize * hFontToPixelRatio)
@ -25,11 +24,11 @@ func CharacterAnalyse(character string) string{
panic(err) panic(err)
} }
face := nerdFont.Face(fontSize, canvas.Black, canvas.FontBold, canvas.FontNormal) face := nerdFont.Face(fontSize, canvas.White, canvas.FontNormal, canvas.FontNormal)
background := canvas.Rectangle(ctx.Width() + 1, ctx.Height() + 1); background := canvas.Rectangle(ctx.Width() + 1, ctx.Height() + 1);
ctx.SetFillColor(canvas.White) ctx.SetFillColor(canvas.Black)
ctx.DrawPath(0, 0, background) ctx.DrawPath(0, 0, background)
ctx.DrawText(0, 1, canvas.NewTextLine(face, character, canvas.Left)) ctx.DrawText(0, 1, canvas.NewTextLine(face, character, canvas.Left))

View File

@ -18,7 +18,7 @@ type Pixel struct {
A int A int
} }
func averagePixel(arr []Pixel) Pixel { func AveragePixel(arr []Pixel) Pixel {
l := len(arr) l := len(arr)
var sumR, sumG, sumB, sumA int var sumR, sumG, sumB, sumA int
for _, v := range arr { for _, v := range arr {

View File

@ -39,7 +39,7 @@ func squashMatrix(pix [][]Pixel) [][]Pixel{
for x := range tensor { for x := range tensor {
for y := range tensor[x] { for y := range tensor[x] {
p := averagePixel(tensor[x][y]) p := AveragePixel(tensor[x][y])
out[y][x] = p out[y][x] = p
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 801 B