for each color c1: for each color c2 already used: if |c1 - c2| < threshold: place c1 next to c2 if c1 hasn't been placed yet: place c1 at a random location