Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:34:24+00:00 2026-05-26T10:34:24+00:00

I have a function f(x,y), mostly monotonic, which produces some values in the range

  • 0

I have a function f(x,y), mostly monotonic, which produces some values in the range {0.0 .. 100.0}. I would like to draw them using different colors as a 2D picture, where (x,y) are coordinates and where distinctive colors stand for distinctive values of the function. The problem is following: I don’t know how to map the values of this function to RGB color space preserving the order (visibly). I have found that smth. like:

R = f(x,y) * 10.0f;
G = f(x,y) * 20.0f;
B = f(x,y) * 30.0f;
color = B<<16|G<<8|R; //@low-endian

works fine, but the resulting picture is too dark. If I increase these constants, it makes things not better, because at some moment a color component will be greater than 0xFF, so it will overflow (one color component should be in the range {0 .. 0xFF}.

Do you have any idea how to map values from {0.0 .. 100.0} to
RGB=[{0 .. 0xFF}<<16|{0 .. 0xFF}<<8|{0 .. 0xFF}] so that the resulting RGB values are visibly Ok?

PS: maybe you know, where to find more info about related theory online? I remember only Comp.Graphics by Foley/Van Dam, but I don’t have this book.

UPDATE: I am looking for how to generate a chroma palette like one on the right:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:34:25+00:00Added an answer on May 26, 2026 at 10:34 am

    You could just try clamping the values to a maximum of 255 (0xff).

    R = min((int)(f(x,y) * 10.0f), 0xff);
    G = min((int)(f(x,y) * 20.0f), 0xff);
    B = min((int)(f(x,y) * 30.0f), 0xff);
    

    Edit: There are a lot of different ways to convert to colors automatically, but you might find that none of them generates the exact progression you’re looking for. Since you already have a picture of an acceptable palette, one method would be to create a lookup table of 256 colors.

    #define RGB(R,G,B) (B<<16|G<<8|R)
    
    int palette[256] = { RGB(0,0,0), RGB(0,0,128), ... };
    
    int greyscale = (int)(f(x,y) * 2.559999);
    assert(greyscale >= 0 && greyscale <= 255);
    int rgb = palette[greyscale];
    

    If the lookup table is too much trouble, you could also break the greyscale range into different subranges and do a linear interpolation between the endpoints of each range.

    int interpolate(int from, int to, double ratio)
    {
        return from + (int)((to - from) * ratio); 
    }
    if (greyscale <= 48)
    {
        R = 0;
        G = 0;
        B = interpolate(0, 255, greyscale/48.0);
    }
    else if (greyscale <= 96)
    {
        R = 0;
        G = interpolate(0, 255, (greyscale-48)/48.0);
        B = interpolate(255, 0, (greyscale-48)/48.0);
    }
    else if ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have classes that are mostly just wrappers around some STL container, like
i have a c function which returns a long double . i'd like to
I'm trying to draw a simple line graph which would use values from the
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
I've got a function called updateTheValue() that I have called using [self updateTheValue] for
I have three tree view controls which house different (but mostly similar data), as
I have a project which will be made up mostly of Java Servlets, JSP/Html
I am very new to spring and java. I have been using mostly springsource.org
I have 1 table (meetings) containing some occursion unix timestamps (dates), mostly upcoming meetings

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.