libfic: Create a color randomization function

This commit is contained in:
nemunaire 2025-03-25 18:54:36 +01:00
parent b62369f89f
commit 590a55c395
2 changed files with 11 additions and 7 deletions

View File

@ -3,7 +3,6 @@ package api
import (
"fmt"
"log"
"math/rand"
"net/http"
"strconv"
"strings"
@ -348,7 +347,7 @@ func importTeamsFromCyberrange(c *gin.Context) {
exist_team.ExternalId = crteam.UUID
_, err = exist_team.Update()
} else {
_, err = fic.CreateTeam(crteam.Name, 0, crteam.UUID)
_, err = fic.CreateTeam(crteam.Name, fic.RandomColor().ToRGB(), crteam.UUID)
}
if err != nil {
@ -375,11 +374,7 @@ func createTeam(c *gin.Context) {
}
if ut.Color == 0 {
ut.Color = fic.HSL{
H: rand.Float64(),
S: 1,
L: 0.5,
}.ToRGB()
ut.Color = fic.RandomColor().ToRGB()
}
team, err := fic.CreateTeam(strings.TrimSpace(ut.Name), ut.Color, ut.ExternalId)

View File

@ -3,6 +3,7 @@ package fic
import (
"bytes"
"crypto/md5"
"math/rand"
"regexp"
"strings"
)
@ -187,3 +188,11 @@ func (c HSL) ToRGB() (rgb uint32) {
return r*65536 + g*256 + b
}
func RandomColor() HSL {
return HSL{
H: rand.Float64(),
S: 1,
L: 0.5,
}
}