libfic: Create a color randomization function
This commit is contained in:
parent
b62369f89f
commit
590a55c395
@ -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)
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user