Generic color sorting. This requires a lot of updates, but is a nice solution. It needs to know the number of colors up front though.