Skip to content

Commit

Permalink
🎨 Gradient colors are now joint by strings.Join()
Browse files Browse the repository at this point in the history
  • Loading branch information
keelus committed Jul 28, 2023
1 parent 4bd1ec2 commit 747ecf2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
12 changes: 1 addition & 11 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,8 @@ func RandomValue(min, max int) int {
return rand.Intn(max-min+1) + min
}

// TODO: Optimisation
func GetGradientStr(gradientColors []string) string {
gradientStr := ""
last := len(gradientColors) - 1
for i, hexStr := range gradientColors {
gradientStr += "#" + hexStr
if i != last {
gradientStr += ","
}
}

return gradientStr
return "#" + strings.Join(gradientColors, ",#")
}

func GradientExists(gradientToCheck string, gradientsSlice [][]string) bool {
Expand Down
10 changes: 2 additions & 8 deletions server/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"html/template"
"math"
"math/rand"
"strings"
"time"

"github.com/gin-contrib/multitemplate"
Expand Down Expand Up @@ -38,14 +39,7 @@ func Renderer() multitemplate.Renderer {
return show
},
"gradientString": func(gradientColors []string) string {
finalString := ""
for i, color := range gradientColors {
finalString += "#" + color
if i != len(gradientColors)-1 {
finalString += ","
}
}
return finalString
return "#" + strings.Join(gradientColors, ",#")
},
"isActiveColor": func(color string) bool {
activeColor := config.LedActive.Color[0]
Expand Down

0 comments on commit 747ecf2

Please sign in to comment.