Leonard Ritter

@lritter@mastodon.gamedev.place

got nerd sniped into quantifying the quality of a palette arrangement and performing random swaps to optimize it.

August 10, 2025 at 4:09:40 PM
(Edited)

have an algo idea for this one: gradients trade colors with each other. each gradient figures out its least fitting element (high variance relative to quadratic curve) and expels it on a pile. then it picks from the pile the most fitting element. if multiple gradients want the same color, the best fit wins. if no gradient wants a color, that's a new gradient (after two consecutively unwanted colors). self-assembling gradients trading piles.

hmmm. that's almost a point cloud meshing algo...

step 1: we start with a single "gradient" that contains all colors. we fit the set to a 3d line, then sort colors by projected position on the line. then we concat all gradient groups (currently 1) back into the linear palette. the result looks ordered, but has high variance.

now the gradient has to expel its worst samples. i'll try expelling two, which form a new gradient. actually, why not find the mean variance and split the set by that.

expelling all colors above mean variance onto the pile, then making a gradient from the pile; we don't split gradients once they would have fewer than 3 colors. doing this repeatedly until none can be split further, we get the second image. clearly we need to redistribute pile colors at some point.

now only letting each gradient expel 1 worst sample onto pile if variance is above threshold; each pile color is then auctioned off to the gradient whose variance it would improve the most, by a factor. then all gradients smaller than 3 are broken up and their colors put on the pile. if the pile size is >= 3, it becomes a new gradient. otherwise we run again.

clearly only the very first gradient benefits from this, others don't grow, and we end up with 104 tiny gradients.

hmhm.

Elk Logo

Welcome to Elk!

Elk is a nimble Mastodon web client. You can login to your Mastodon account and use it to interact with the fediverse.

Expect some bugs and missing features here and there. Elk is Open Source and we're actively improving it as a community project. Join us and let's build it together!

If you'd like to report a bug, help us testing, give feedback, or contribute, reach out to us on GitHub and get involved.

To boost development, you can sponsor the Team through GitHub Sponsors. We hope you enjoy Elk!

PatakDaniel Roe三咲智子 Kevin DengAnthony FuTAKAHASHI ShuujiJoaquín Sánchez

The Elk Team