?
Solved

random bright coloe

Posted on 2003-02-20
5
Medium Priority
?
222 Views
Last Modified: 2010-03-31
i can generate random color but sometimes the  color gets to dark anyway to solve this problem? below is how random color is generated

int red =  ( int ) ( Math.random ( ) * 256 );
etc
etc
0
Comment
Question by:bobbybuilder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 7988733
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7988743
The idea being, you can leave the brightness high and simply vary the hue and saturation
0
 

Author Comment

by:bobbybuilder
ID: 7994939
i have tried it, my attempt is below is that the way to go about it. i still have to fiddle with the numbers as i still get dark colors  

int red =  ( int ) ( Math.random ( ) * 256 ); <-should these be float or it does not matter
   int blue =   ( int ) ( Math.random ( ) * 256 );
   int green = ( int ) ( Math.random ( ) * 256 );
     
   Color c = new Color(red,blue,green);  

c.getHSBColor( (float) 500 ,(float) 0.1 , (float) 1.0);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 7996252
This is the sort of thing i mean:

import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

public class RandomColor {

  public static void main(String[] args){
    JFrame f = new JFrame();
    ShapePanel shapePanel = new ShapePanel();
    f.getContentPane().add(shapePanel);
    new Thread(shapePanel).start();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(300, 200);
    f.setVisible(true);
  }

}

class ShapePanel extends JPanel implements Runnable {
  boolean highlighted;
  Shape shape;
  Paint currentPaint;

  public ShapePanel() {
    super();
    shape = new Rectangle2D.Float(0.f, 0.f, 100.f, 50.f);
    currentPaint = Color.red;
  }

  public void paintComponent(Graphics _g) {
    Graphics2D g = (Graphics2D)_g;
    g.setPaint(currentPaint);
    g.fill(shape);
    g.draw(shape);
  }

  public Paint getCurrentPaint() {
    return Color.getHSBColor((float)Math.random(), (float)Math.random(), 1.0f);
  }


  public void run() {
    while (true) {
      try {
        Thread.sleep(1000);
        currentPaint = getCurrentPaint();
        repaint();
      }
      catch(Exception e){
        e.printStackTrace();
      }
    }
  }

}
0
 

Author Comment

by:bobbybuilder
ID: 7996517
thxs
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question