mirror of
https://github.com/muesli/kmeans.git
synced 2025-10-30 02:11:52 +08:00
Simplify colorpalette's example code
This commit is contained in:
@@ -32,21 +32,17 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Color struct {
|
type Color struct {
|
||||||
color colorful.Color
|
colorful.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Color) Coordinates() clusters.Coordinates {
|
func (c Color) Coordinates() clusters.Coordinates {
|
||||||
l, a, b := c.color.Lab()
|
l, a, b := c.Lab()
|
||||||
return clusters.Coordinates{
|
return clusters.Coordinates{l, a, b}
|
||||||
l,
|
|
||||||
a,
|
|
||||||
b,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Color) Distance(pos clusters.Coordinates) float64 {
|
func (c Color) Distance(pos clusters.Coordinates) float64 {
|
||||||
c2 := colorful.Lab(pos[0], pos[1], pos[2])
|
c2 := colorful.Lab(pos[0], pos[1], pos[2])
|
||||||
return c.color.DistanceLab(c2)
|
return c.DistanceLab(c2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -62,9 +58,7 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
d = append(d, Color{
|
d = append(d, Color{c})
|
||||||
color: c,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user