Total members 11892 |It is currently Thu Sep 19, 2024 11:15 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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!




Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

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:
File comment: hsb
hsb.GIF
hsb.GIF [ 10.09 KiB | Viewed 5211 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

For this message the author DrRakha has received gratitude : maramira
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Color representation in Java
 Gradient Color in java     -  
 java Color Components     -  
 Changing the color of a graph draw in java     -  
 Ball Color Match 2D Java Game Version 1.0     -  
 Color and CSS     -  
 Changing link color     -  
 Draw char with color in php     -  
 change background color with RGB     -  
 skymiles background color     -  
 Set border bottom color     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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