-
Notifications
You must be signed in to change notification settings - Fork 71
/
spaced.go
62 lines (56 loc) · 1.9 KB
/
spaced.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2023, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package colors
import (
"image/color"
"cogentcore.org/core/colors/cam/hct"
"cogentcore.org/core/colors/matcolor"
)
// Spaced returns a maximally widely spaced sequence of colors
// for progressive values of the index, using the HCT space.
// This is useful, for example, for assigning colors in graphs.
func Spaced(idx int) color.RGBA {
if matcolor.SchemeIsDark {
return SpacedDark(idx)
}
return SpacedLight(idx)
}
// SpacedLight is the Light mode version of Spaced
func SpacedLight(idx int) color.RGBA {
// red, blue, green, yellow, violet, aqua, orange, blueviolet
// hues := []float32{30, 280, 140, 110, 330, 200, 70, 305}
hues := []float32{25, 255, 150, 105, 340, 210, 60, 300}
// even 45: 30, 75, 120, 165, 210, 255, 300, 345,
toffs := []float32{0, -10, 0, 5, 0, 0, 5, 0}
tones := []float32{65, 80, 45, 65, 80}
chromas := []float32{90, 90, 90, 20, 20}
ncats := len(hues)
ntc := len(tones)
hi := idx % ncats
hr := idx / ncats
tci := hr % ntc
hue := hues[hi]
tone := toffs[hi] + tones[tci]
chroma := chromas[tci]
return hct.New(hue, float32(chroma), tone).AsRGBA()
}
// SpacedDark is the Dark mode version of Spaced
func SpacedDark(idx int) color.RGBA {
// red, blue, green, yellow, violet, aqua, orange, blueviolet
// hues := []float32{30, 280, 140, 110, 330, 200, 70, 305}
hues := []float32{25, 255, 150, 105, 340, 210, 60, 300}
// even 45: 30, 75, 120, 165, 210, 255, 300, 345,
toffs := []float32{0, -10, 0, 10, 0, 0, 5, 0}
tones := []float32{65, 80, 45, 65, 80}
chromas := []float32{90, 90, 90, 20, 20}
ncats := len(hues)
ntc := len(tones)
hi := idx % ncats
hr := idx / ncats
tci := hr % ntc
hue := hues[hi]
tone := toffs[hi] + tones[tci]
chroma := chromas[tci]
return hct.New(hue, float32(chroma), tone).AsRGBA()
}