Wed Oct 07, 2009 1:55 pm
Hi everybody!
I am trying to color some lines gradually, depending on one variable, speed, namely if the value of the variable is really small I need a strong color otherwise a more blurry one, even white.
The variable I have is speed so it is varying between 20 and 120 usually.
I tried two ways for doing this but non of them is working :-S All I get is a black color a bit less darker when speed decreases, but u can hardly see the difference.
First try :
float hue = (float) 0.6;
float saturation = (float) (1.0 - speed / 130.0);
float brightness = (float) (1.0 - speed / 130.0);
g2d.setColor(Color.getHSBColor(hue, saturation, brightness));
width = 10;
Second:
g2d.setColor(new Color((float) ((1.0 - speed / 130.0)*(1.0 - speed / 130.0)), (float) (1.0 - speed / 130.0), (float) (1.0 - speed / 130.0)));
I would really appreciate any advice!
Wed Oct 07, 2009 5:44 pm
I think you have to change only the
Saturation java code
package test;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
public class HSBColors extends JFrame{
public HSBColors()
{
setTitle("HSBColor Frame");
setSize(500,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D graphics2D = (Graphics2D) g;
float h = 0f ;
float s = 0.9f ;
int b = 1 ;
graphics2D.setColor(Color.getHSBColor(h, s, b));
graphics2D.fillRect(10, 10, 300, 300);
}
public static void main(String[] args)
{
new HSBColors().setVisible(true);
}
}
- Attachments
-
- hsb
- hsb.GIF (10.09 KiB) Viewed 5246 times
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.