cycle throw nerdfont icons
This commit is contained in:
parent
3bf398fcad
commit
ab9eb8e798
|
@ -0,0 +1 @@
|
||||||
|
tmp/
|
|
@ -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")
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -111,4 +111,3 @@ func GetChar(brightness float64) string {
|
||||||
}
|
}
|
||||||
return char
|
return char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
9327
nerdfont.txt
9327
nerdfont.txt
File diff suppressed because it is too large
Load Diff
|
@ -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))
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 |
Loading…
Reference in New Issue