add split string func

This commit is contained in:
2024-08-15 16:18:55 +07:00
parent 31b2d6c793
commit d1b04676a7
6 changed files with 43 additions and 43 deletions

View File

@@ -1,28 +0,0 @@
package utils
import (
"fmt"
"math"
)
// InterpolateColor calculates a color between two given colors based on progress (0 to 1)
func InterpolateColor(start, end string, progress float64) string {
r1, g1, b1 := HexToRGB(start)
r2, g2, b2 := HexToRGB(end)
r := int(math.Round(float64(r1)*(1-progress) + float64(r2)*progress))
g := int(math.Round(float64(g1)*(1-progress) + float64(g2)*progress))
b := int(math.Round(float64(b1)*(1-progress) + float64(b2)*progress))
return fmt.Sprintf("#%02x%02x%02x", r, g, b)
}
// Helper function to convert hex to RGB
func HexToRGB(hex string) (int, int, int) {
var r, g, b int
_, err := fmt.Sscanf(hex, "#%02x%02x%02x", &r, &g, &b)
if err != nil {
return 0, 0, 0
}
return r, g, b
}

View File

@@ -0,0 +1,18 @@
package utils
import "strings"
func SplitStrings(text string, count int) string {
words := strings.Split(text, " ")
var result strings.Builder
for i := 0; i < len(words); i += count {
if i+count < len(words) {
result.WriteString(strings.Join(words[i:i+count], " ") + "\n")
} else {
result.WriteString(strings.Join(words[i:], " "))
}
}
return result.String()
}