Skip to content

Commit a83ff67

Browse files
committed
(tern. plot.) implemented the elemental color scheme for N-components
1 parent 6d51084 commit a83ff67

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

utils/ternaryPlot.nim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const
5757
sideWidth: float = (60*scaling)
5858
luminance: float = if compIsMain: 0.55 else: 0.45
5959
alpha: uint8 = if compIsMain: 255 else: 128
60-
# Color schemes
60+
# A couple of hard-coded color schemes (2-5 components) which look nice
6161
colorSchemeOKlab2c: seq[seq[float]] = @[
6262
@[luminance, 0.250*scaleChroma, 0.000],
6363
@[luminance, -0.250*scaleChroma, 0.000]]
@@ -83,14 +83,23 @@ const
8383
@[0.400, 0.217*scaleChroma, 0.125*scaleChroma],
8484
@[1.0, 0.0, 0.0]]
8585

86+
87+
8688
# *** Color Schemes ***
8789
const colorSchemeOKlab: seq[seq[float]] = static:
90+
func colorSchemeOKlabNc(n: int): seq[seq[float]] =
91+
for i in 0..<n:
92+
let
93+
angle = 2 * PI * i.float / n.float
94+
a = 0.250 * scaleChroma * cos(angle)
95+
b = 0.250 * scaleChroma * sin(angle)
96+
result.add(@[luminance, a, b])
8897
case elementalEmbeddingLen:
8998
of 2: colorSchemeOKlab2c
9099
of 3: colorSchemeOKlab3c
91100
of 4: colorSchemeOKlab4c
92101
of 5: colorSchemeOKlab5c
93-
else: raise newException(ValueError, "Unsupported number of components")
102+
else: colorSchemeOKlabNc(elementalEmbeddingLen)
94103

95104
const propertyColoringOKlab: seq[seq[float]] = static:
96105
case propetyColoringStyle:

0 commit comments

Comments
 (0)