Skip to content

Instantly share code, notes, and snippets.

@yurkimus
Created January 5, 2024 17:08
Show Gist options
  • Save yurkimus/aa13586e3009c26689cba198ee36d271 to your computer and use it in GitHub Desktop.
Save yurkimus/aa13586e3009c26689cba198ee36d271 to your computer and use it in GitHub Desktop.
Average of 3-color tuples
const hexs = [
// Karjala
[ '538854', 'be2928', '000000' ],
// Ludic
[ '529f54', 'be2928', '3d3b7b' ],
// Veps
[ '16b370', 'ffff00', '155cdc' ],
// Russian-side Finnish
[ 'ffd301', 'ef2d20', '0167b3' ],
// Izhorian
[ '000080', 'fed801', 'd70000' ],
// Votic
[ 'ffffff', '0099ff', 'ff0000' ],
// Siberian-Estonian
[ 'ffffff', 'ee0013', '150068' ]
]
const parseHex = flip(parseInt)(16)
const toHex = invoker(1, 'toString')(16)
const average = converge(
divide,
[
reduce(useWith(add, [identity, parseHex]), 0),
length
]
)
const mix = compose(
map(compose(toHex, Math.round, average)),
transpose
)
mix(hexs) // => ["88ab3a", "c39013", "5224a3"]
@yurkimus
Copy link
Author

yurkimus commented Jan 5, 2024

1: Original output
2. Manually corrected

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment