[java2D] colored gradient

Discussion in 'Java' started by markus brosch, Aug 18, 2003.

  1. Hi *

    I am looking for a solution for a "rainbow" colored gradient.

    At the moment I have a white ... black solution which represents values
    from 0 to 100 (new GradientPaint(x,y,Color.black,Color.white))

    I want to try to use a rainbow color gradient, because it is more easy to
    guess the values in between white and black. I hope you know what I
    mean by rainbow color gradient ...

    How can I set up such a gradient?
    Anyway, if this question is to unprecise, let me know ;-)

    Cheers, Markus
     
    markus brosch, Aug 18, 2003
    #1
    1. Advertising

  2. On Mon, 18 Aug 2003 13:40:05 +0200, S. Balk wrote:
    > GradientPaint redToYellow =
    > new GradientPaint(x,y,Color.RED,x,y,Color.YELLOW));
    > GradientPaint yellowToGreen =
    > new GradientPaint(x,y,Color.YELLOW,x,y,Color.GREEN));
    > etc. etc.


    Thanks!

    I want to map Integer values between 0 and 100 and this was
    actually in my white/black solution quite simple. Now it's a little bit
    more work, because I have to map only parts of it to the right color. But
    it should't be that hard ;-)

    Best regards!
     
    markus brosch, Aug 18, 2003
    #2
    1. Advertising

  3. markus brosch

    S. Balk Guest

    > I want to try to use a rainbow color gradient,
    >
    > How can I set up such a gradient?




    private TexturePaint rainbowTexture = null;

    public void initRainbowTexture()
    {
    BufferedImage buffer = ...;
    Graphics2D gBuffer = image.createGraphics();

    GradientPaint redToYellow =
    new GradientPaint(x,y,Color.RED,x,y,Color.YELLOW));
    GradientPaint yellowToGreen =
    new GradientPaint(x,y,Color.YELLOW,x,y,Color.GREEN));
    etc. etc.

    gBuffer.setPaint(redToYellow);
    gBuffer.fill(new Rectangle(x,y,w,h));

    gBuffer.setPaint(yellowToGreen);
    gBuffer.fill(new Rectangle(x,y,w,h));
    etc. etc.

    gBuffer.dispose();
    }



    public void paintComponent(Graphics g)
    {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D)g;

    if(rainbowTexture == null)
    {
    this.initRainbowTexture();
    }

    Shape graph = ...;
    g2d.setPaint(rainbowTexture);
    g2d.fill(graph);

    g2d.dispose();
    }
     
    S. Balk, Aug 18, 2003
    #3
  4. "markus brosch" <> writes:
    > I want to try to use a rainbow color gradient, because it is more easy to
    > guess the values in between white and black. I hope you know what I
    > mean by rainbow color gradient ...


    Yes, I think so. If I remember the details correctly, you get one by
    using multiple gradients, going from rainbow-color to rainbow-color.
    However, the exact number and type of colors in such a gradient is not
    "standardised". E.g. you can get one by using four gradients and going
    from blue to magenta to red to orange and to yellow (popular in some
    scientific applications). Or use the more classic order: red, orange,
    yellow, green, blue, (dark) magenta. And that still leaves anil
    (indigo) out from the classic list of the seven colors of the rainbow,
    which is supposed to come between blue and magenta.

    /Thomas
     
    Thomas Weidenfeller, Aug 18, 2003
    #4
  5. markus brosch

    S. Balk Guest

    > For my black and white gradient I just use this (no real mapping):
    >
    > int rgb = 255 - (value * 255); // value from 0 to 1 (0 to 100%)
    > g2d.setColor(new Color(rgb, rgb, rgb)); // grey between white and black


    use HSB colors, changing the H(ue)
     
    S. Balk, Aug 18, 2003
    #5
  6. markus brosch

    Roedy Green Guest

    Roedy Green, Aug 18, 2003
    #6
  7. markus brosch

    Roedy Green Guest

    On Mon, 18 Aug 2003 15:35:36 +0200, "S. Balk"
    <0spam.nl> wrote or quoted :

    >use HSB colors, changing the H(ue)


    to get an idea what that would look like, see the Netscape colours
    sorted in various orders including by saturation and hue.

    see http://mindprod.com/jgloss/colour.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Aug 18, 2003
    #7
  8. On Mon, 18 Aug 2003 15:35:36 +0200, S. Balk wrote:

    > use HSB colors, changing the H(ue)


    That's it - thanks ;-)
    Fits exactly my needs ... for the moment.

    Best regards, Markus
     
    markus brosch, Aug 19, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marco Schmidt

    Re: Using Component based on Java2D

    Marco Schmidt, Jul 1, 2003, in forum: Java
    Replies:
    0
    Views:
    799
    Marco Schmidt
    Jul 1, 2003
  2. Bura Tino

    Java2D transparency: a long delay

    Bura Tino, Jul 1, 2003, in forum: Java
    Replies:
    4
    Views:
    1,206
    S. Balk
    Jul 2, 2003
  3. Will Clark

    360degree rotation in Java2D

    Will Clark, Aug 28, 2003, in forum: Java
    Replies:
    3
    Views:
    3,160
    Knute Johnson
    Sep 4, 2003
  4. Karl Mueller
    Replies:
    1
    Views:
    1,934
    Karl Mueller
    Jan 8, 2004
  5. muckyduck
    Replies:
    0
    Views:
    330
    muckyduck
    Jan 26, 2004
Loading...

Share This Page