libfic: Create a color randomization function
This commit is contained in:
parent
b62369f89f
commit
590a55c395
@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -348,7 +347,7 @@ func importTeamsFromCyberrange(c *gin.Context) {
|
|||||||
exist_team.ExternalId = crteam.UUID
|
exist_team.ExternalId = crteam.UUID
|
||||||
_, err = exist_team.Update()
|
_, err = exist_team.Update()
|
||||||
} else {
|
} else {
|
||||||
_, err = fic.CreateTeam(crteam.Name, 0, crteam.UUID)
|
_, err = fic.CreateTeam(crteam.Name, fic.RandomColor().ToRGB(), crteam.UUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -375,11 +374,7 @@ func createTeam(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ut.Color == 0 {
|
if ut.Color == 0 {
|
||||||
ut.Color = fic.HSL{
|
ut.Color = fic.RandomColor().ToRGB()
|
||||||
H: rand.Float64(),
|
|
||||||
S: 1,
|
|
||||||
L: 0.5,
|
|
||||||
}.ToRGB()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
team, err := fic.CreateTeam(strings.TrimSpace(ut.Name), ut.Color, ut.ExternalId)
|
team, err := fic.CreateTeam(strings.TrimSpace(ut.Name), ut.Color, ut.ExternalId)
|
||||||
|
@ -3,6 +3,7 @@ package fic
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"math/rand"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -187,3 +188,11 @@ func (c HSL) ToRGB() (rgb uint32) {
|
|||||||
|
|
||||||
return r*65536 + g*256 + b
|
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