Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wouldn't use just completely random colors. You'd get completely different saturations and brightnesses which will look plain ugly.</p> <p>You could fix a saturation (choose a high value for vibrant colors) and brightness and choose a random hue value, but you would run the risk of getting two consecutive pie-slices with almost the same color.</p> <p>I would compute a set of spread out hue-values as shown in the answer to this question:</p> <ul> <li><a href="https://stackoverflow.com/questions/3403826/how-to-dynamically-compute-a-list-of-colors">How to dynamically compute a list of colors?</a></li> </ul> <p>Reposting the answer below</p> <hr> <pre><code>import java.awt.*; public class TestComponent extends JPanel { int numCols = 6; public void paint(Graphics g) { float h = 0, dh = (float) getHeight() / numCols; Color[] cols = getDifferentColors(numCols); for (int i = 0; i &lt; numCols; i++) { g.setColor(cols[i]); g.fillRect(0, (int) h, getWidth(), (int) (h += dh)); } } public static Color[] getDifferentColors(int n) { Color[] cols = new Color[n]; for (int i = 0; i &lt; n; i++) cols[i] = Color.getHSBColor((float) i / n, 1, 1); return cols; } public static void main(String s[]) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new TestComponent()); f.setSize(400, 400); f.setVisible(true); } } </code></pre> <p><img src="https://i.stack.imgur.com/oC4Yy.png" alt="enter image description here"></p> <p>If you need like more than 30 colors, you could of course change the brightness and perhaps the saturation as well, and have, for instance, 10 dark colors, 10 midtone colors, and 10 bright colors.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload