我想在Java应用程序中的JPanel上随机绘制彩色点。有没有什么方法可以创建随机颜色?
发布于 2013-11-17 22:46:07
随机RGB值的一行代码:
new Color((int)(Math.random() * 0x1000000))
发布于 2010-11-22 23:45:08
如果你想要令人愉悦的、柔和的颜色,最好使用HLS系统。
final float hue = random.nextFloat();
// Saturation between 0.1 and 0.3
final float saturation = (random.nextInt(2000) + 1000) / 10000f;
final float luminance = 0.9f;
final Color color = Color.getHSBColor(hue, saturation, luminance);
发布于 2012-01-05 15:54:09
将此复制粘贴为鲜艳的柔和彩虹颜色
int R = (int)(Math.random()*256);
int G = (int)(Math.random()*256);
int B= (int)(Math.random()*256);
Color color = new Color(R, G, B); //random color, but can be bright or dull
//to get rainbow, pastel colors
Random random = new Random();
final float hue = random.nextFloat();
final float saturation = 0.9f;//1.0 for brilliant, 0.0 for dull
final float luminance = 1.0f; //1.0 for brighter, 0.0 for black
color = Color.getHSBColor(hue, saturation, luminance);
https://stackoverflow.com/questions/4246351
复制相似问题