mirror of
https://github.com/taigrr/simplecolorpalettes.git
synced 2026-04-01 20:49:11 -07:00
use builtins, add joining funcs
This commit is contained in:
@@ -33,6 +33,34 @@ func (n NamedPalette) ToPalette() color.Palette {
|
||||
return color.Palette(x)
|
||||
}
|
||||
|
||||
func (a SimplePalette) Sort() SimplePalette {
|
||||
sort.Sort(a)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a SimplePalette) Join(b SimplePalette) SimplePalette {
|
||||
m := make(map[SimpleColor]SimpleColor)
|
||||
r := SimplePalette{}
|
||||
for _, c := range a {
|
||||
m[c] = c
|
||||
}
|
||||
for _, c := range b {
|
||||
m[c] = c
|
||||
}
|
||||
for _, c := range m {
|
||||
r = append(r, c)
|
||||
}
|
||||
sort.Sort(r)
|
||||
return r
|
||||
}
|
||||
|
||||
func (s SimplePalette) Get(index int) SimpleColor {
|
||||
if index < 0 || index > len(s) {
|
||||
return FromHexString("#66042d")
|
||||
}
|
||||
return s[index]
|
||||
}
|
||||
|
||||
func (s SimplePalette) ToPalette() color.Palette {
|
||||
var x color.Palette
|
||||
for _, c := range s {
|
||||
@@ -68,6 +96,13 @@ func (input SimpleColor) ToExtendedAnsi() SimpleColor {
|
||||
return SimpleColor(uint32(r)<<16 + uint32(g)<<8 + b)
|
||||
}
|
||||
|
||||
func (p NamedPalette) ToExtendedAnsi() NamedPalette {
|
||||
for k, v := range p {
|
||||
p[k] = v.ToExtendedAnsi()
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p SimplePalette) ToExtendedAnsi() (sp SimplePalette) {
|
||||
used := make(map[SimpleColor]bool)
|
||||
for _, x := range p {
|
||||
|
||||
Reference in New Issue
Block a user