java - 如何更改HSB颜色系统中的颜色

标签 java

我正在研究此 post 的最后一个答案中的示例代码

看看如何制作一个好的闪烁按钮。该示例代码使用以下代码来指定颜色:

           for (int i = 0; i < N; i++) 
            {                 
                clut.add(Color.getHSBColor(1, 1 - (i / N), 1));             
            }             
            for (int i = 0; i < N; i++) 
            {                 
                clut.add(Color.getHSBColor(1, i / N, 1));             
            } 

Color.getHSBColor(1, 1 - (i/N), 1) 是构建颜色的地方。 getHSBColor() 的第一个参数 (Hue) 将指定基色。因此,如果我将其更改为230,则颜色应该是基于蓝色的颜色;如果是60,则颜色应基于黄色。但示例程序并没有按照我的预期工作。将色相设置为不同的值后,没有闪烁的颜色变化。有人知道为什么吗?

最佳答案

Color.getHSBColor() 应接收从 0 到 1 的 float ,因此任何大于 1 的值都将被视为 1...

看一下:

The hue parameter is a decimal number between 0.0 and 1.0 which indicates the hue of the color. You'll have to experiment with the hue number to find out what color it represents.

For example, setPenColor(Color.getHSBColor(0.56f, 1.0f, 0.8f));

来源:http://www.otherwise.com/Lessons/ColorsInJava.html

例如,您可以这样做:

        float hue = your_color/255; // if you want to use 0-255 range

        for (int i = 0; i < N; i++) {                 
            clut.add(Color.getHSBColor(hue, 1 - (i / N), 1));             
        }             
        for (int i = 0; i < N; i++) {                 
            clut.add(Color.getHSBColor(hue, i / N, 1));             
        } 

关于java - 如何更改HSB颜色系统中的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7488117/

相关文章:

java - Android Studio 如何在静态方法中引用 Activity 本身

java - 布局 Inflate 中的alignParentBottom

java - 当rmi编译器创建 stub 类文件时

java - 具有增强 for 循环的 ClassCastException

java - 执行目标 maven-failsafe-plugin : (failsafe-integration-tests) project x: suiteXmlFiles is configured, 但没有 TestNG 依赖

java - 如何将不带 Z 的 Java 日期转换为带 Z 的日期

java - 处理后将对象设置为 null 是一种好习惯吗?

java - 我如何更改我的 Eclipse 源格式化程序设置来处理以下示例?

java - FlowLayout对象中的组件setSize方法

java - 防止 JTextField 中出现字母数字