Would this algorithm be of any use, @DevAndArtist ?