Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 9:47 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: Color representation in Java
PostPosted: Wed Oct 07, 2009 1:55 pm 
Offline
Newbie
User avatar

Joined: Wed Oct 07, 2009 1:45 pm
Posts: 1
Has thanked: 1 time
Have thanks: 0 time

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!


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Color representation in Java
PostPosted: Wed Oct 07, 2009 5:44 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
I think you have to change only the Saturation

This what i understood from this link http://www.web-colors-explained.com/hsb.php and i tried the code :
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 1191 times ]

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )

For this message the author msi_333 has received gratitude : maramira
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 Java seminar topic with demo  Java  Anonymous  1
 java project code  Java  Anonymous  0
 change Font of text in java  Java examples  msi_333  1
 Changing the color and properties of the header tag  HTML examples  msi_333  0
 Read your gmail using Java code  Java examples  msi_333  5

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team