NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: Colour Scaling Control

Hi all,

Perhaps Bill forgot to say (as it has already been pointed out in the
Tutorial ;-) that colour components vary from 0.0 to 1.0.

> 
> Map colors like this:
> 
>   int TABLE_SIZE = 256; // may be whatever you want
>   ScalarMap rgbMap = new ScalarMap(yourRealType, Display.RGB);
>   display.addMap(rgbMap):
>   rgbMap.setRange(lowValueOfRange, hiValueOfRange);
>   ColorControl rgbControl = (ColorControl) rgbMap.getControl();
>   float [][] table = new float[3][TABLE_SIZE];
>   for (int i=0; i<TABLE_SIZE; i++) {
>     table[0][i] = // red for i-th value
>     table[1][i] = // green for i-th value
>     table[2][i] = // blue for i-th value
>   }
>   rgbControl.setTable(table);
> 

So an application of the above is a colour table varying from green to
red (blue is always zero):
    
    int len = 256;
    float[][] table = new float[3][len];
    
    for (int i=0; i<len; i++) {
      float a = ((float) i) / (float) (len-1);
          table[0][i] =  a;
          table[1][i] = 1.0f - a;
          table[2][i] = 0.0f;
    }
  
Red component increases linearly and green component decreases linearly.
Hope my hint helps...

Yours,

Ugo


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: