1. Home
  2. DCOLOURS procedure

DCOLOURS procedure

Forms a band of graduated colours for graphics (P.W. Goedhart).

Options

METHOD = string token Type of colour band required (spectral, blackbody, linear); default line
PLOT = string token What to plot (testgraph); default *

Parameters

START = scalar or text Start value for the colour band; default * gives an appropriate default for the METHOD concerned
END = scalar, text or variate End value(s) for the colour band; default * gives an appropriate default for the METHOD concerned
GAMMA = scalar or variate The gamma-correction exponent(s) for the colour band; default 1
NCOLOURS = scalar or variate Number(s) of colours in the colour band; default 20
RGB = variates Saves the RGB colour values of each colour band
RED = variates Saves the red component of the RGB colour values
GREEN = variates Saves the green component of the RGB colour values
BLUE = variates Saves the blue component of the RGB colour values
TITLE = text General title for each test graph; default forms an informative title automatically
WINDOW = scalar Window number for each test graph; default 1
SCREEN = string token Whether to clear the screen before plotting each test graph or to continue plotting on the old screen (clear, keep); default clea

Description

Procedure DCOLOURS creates a colour of graduated colours by interpolating between start and end colour values. You can save the RGB colours of the band, in a variate, using the RGB parameter. Alternatively, you can save the red, green and blue components of the colours using the RED, GREEN and BLUE parameters (again in variates).

A test graph displaying the colour band can be requested by setting option PLOT=testgraph. The WINDOW parameter supplies the window number for the plot (default 1). The TITLE parameter can supply a title for the test graph; if this is not set, a suitable title is generated automatically. You can set parameter SCREEN=keep to plot the test graph on an existing screen; by default the screen is cleared first.

The METHOD option provides a choice of three different types of colour band. The default, METHOD=linear, forms the colours by interpolating between start and end RGB values. The start value is specified by the START parameter, as either a scalar defining an RGB colour value, or a text containing the name of one of the pre-defined Genstat colours (see the PEN directive for the available names, or search for “Graphics Colours” in the on-line help). You can set the END parameter to a single scalar or text (giving either the RGB value or the name of the colour) to define the band as a single sequence of colours. Alternatively, you can define a variate or a text with several values to form the band from several sequences of colours. At each END colour, DCOLOURS then begins a new sequence running from that colour to the next END colour. The default values for START and END are 'white' and 'black'.

Setting METHOD=spectral forms an approximate rainbow spectrum for wavelengths between 380 nm and 780 nm. There can now be only a single sequence of colours. The START and END parameters specify the start and end wavelengths, as scalars, with default values of 380 and 780.

The final setting, METHOD=blackbody, forms colours of hot objects with temperatures between 500 K and 11000 K. Again, only a single sequence of colours is allowed. The START and END parameters specify the start and end temperatures, as scalars, with default values of 500 and 11000.

The NCOLOURS parameter specifies the number of colours in each sequence of colours, as a scalar for the spectral or blackbody methods, or as either a scalar or a variate for the linear method; the default is 20.

The red, green and blue values in each sequence are assumed by default to vary linearly with wavelength, temperature or red/green/blue components. Alternatively, you can use the GAMMA parameter to specify the power for a power transformation (default 1). It must be set to a scalar for the spectral or blackbody methods, and to either a scalar or a variate for the linear method. Its values must lie in the interval [0.25, 4].

The number of values specified by each set of END, GAMMA and NCOLOURS parameters can be different. However, the number of values in the setting of the END parameter determines the number of colour sequences in the band, and the values in the GAMMA setting and NCOLOURS setting are recycled as required.

Options: METHOD, PLOT.

Parameters: START, END, GAMMA, NCOLOURS, RGB, RED, GREEN, BLUE, TITLE, WINDOW, SCREEN.

Method

For a single linear colour band the red component is calculated as follows:

VARIATE [VALUES=1...#NCOLOURS] count

CALCULATE count = (count - 1) / (NCOLOURS - 1)

& red = RED(START) + (RED(END) - RED(START)) * count

& red = INTEGER(255 * (red/255)**GAMMA)

Spectral and blackbody colours can be found at www.midnightkite.com/color.html which links to Fortran code for spectral colours at www.physics.sfasu.edu/astro/color/spectra.html, and for blackbody colours at www.physics.sfasu.edu/astro/color/blackbody.html.

Action with RESTRICT

Restrictions are not allowed.

See also

Directive: PEN.

Procedure: GETRGB.

Commands for: Graphics.

Example

CAPTION   'DCOLOURS example'; STYLE=meta
FFRAME    [ROWS=12; COLUMNS=1; MARGIN=none; STARTWINDOW=21;\
          YMUPPER=0.03; YMLOWER=0.02]
PEN       -5; SIZE=0.9
" Default values START='red'; END='green' for spectral, blackbody and linear "
DCOLOURS  [METHOD=spectral; PLOT=test] GAMMA=0.3; WINDOW=21
DCOLOURS  [METHOD=spectral; PLOT=test] GAMMA=1.0; WINDOW=22; SCREEN=keep
DCOLOURS  [METHOD=spectral; PLOT=test] GAMMA=2.0; WINDOW=23; SCREEN=keep
DCOLOURS  [METHOD=blackbody; PLOT=test] GAMMA=0.3; WINDOW=24; SCREEN=keep
DCOLOURS  [METHOD=blackbody; PLOT=test] GAMMA=1.0; WINDOW=25; SCREEN=keep
DCOLOURS  [METHOD=blackbody; PLOT=test] GAMMA=2.0; WINDOW=26; SCREEN=keep
DCOLOURS  [METHOD=linear; PLOT=test] GAMMA=0.3; WINDOW=27; SCREEN=keep
DCOLOURS  [METHOD=linear; PLOT=test] GAMMA=1.0; WINDOW=28; SCREEN=keep
DCOLOURS  [METHOD=linear; PLOT=test] GAMMA=2.0; WINDOW=29; SCREEN=keep
" METHOD=linear using pre-defined colours "
DCOLOURS  [METHOD=linear; PLOT=test] START='red'; 'green'; WINDOW=30;\
          SCREEN=keep
DCOLOURS  [METHOD=linear; PLOT=test] START='red'; 'blue'; WINDOW=31;\
          SCREEN=keep
DCOLOURS  [METHOD=linear; PLOT=test] START='green'; 'blue'; WINDOW=32;\
          SCREEN=keep
" METHOD=linear with multiple stacked colour bands "
TEXT      start[1...10]; VALUE='red', 'green', 'blue', 'yellow', 'fuchsia',\ 
          'coral', 'peru', 'goldenrod', 'silver', 'hotpink'
TEXT      end[1...10]; VALUES=!t(yellow,green), !t(blue, fuchsia, white),\ 
          !t(aqua,red), !t(green,aqua,white), !t(blue,yellow,fuchsia,grey),\ 
          !t(cadetblue, olive, linen), !t(magenta, darkgreen, oldlace),\ 
          !t(chartreuse, plum, orchid), !t(salmon, teal, cyan, beige),\ 
          !t(steelblue, mintcream, sienna)
TEXT      screen; VALUE='clear'
DCOLOURS  [PLOT=test] start[]; END=end[]; WINDOW=21...30; SCREEN=clear,9(keep)
" use colours in a shade plot "
TEXT      [VALUES=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec] Mlab
FACTOR    [LABELS=Mlab] Month
VARIATE   [VALUES=2007...2010] Ylev
FACTOR    [LEVELS=Ylev] Year
TABLE     [CLASSIFICATION=Month,Year; VALUES=\
          -10.97,2.43,0.96,-10.59,\
          0.43,6.49,4.08,5.18,\
          0.20,-2.59,7.63,-17.27,\
          3.44,4.22,18.82,-5.43,\
          -11.73,3.85,6.96,11.82,\
          9.76,10.10,6.19,4.51,\
          3.84,-6.38,3.77,-9.02,\
          -7.06,-9.91,-8.36,-17.99,\
          11.81,4.76,6.52,-4.55,\
          2.45,12.08,2.37,-2.24,\
          8.68,0.78,1.85,9.11,\
          5.88,1.01,-6.33,12.33] Profit
PRINT     Profit
" form groups of profit levels "
GROUPS    [LMETHOD=*; REDEFINE=yes] !(#Profit); FACTOR=Profitfac;\
          LIMITS=!(-21,-19...21)
TABLE     [CLASSIFICATION=Month,Year] Profitgroup; VALUES=Profitfac
" pens running from red - white for =21 "
DCOLOURS  'red'; END=!t(white,blue); NCOLOURS=!(12,11); RGB=rgbvals
PEN       1...23; CAREA=#rgbvals
" select only the pen (group) values that ectually occur in the table "
CALCULATE Pens = UNIQUE(Profitfac)
XAXIS     3; MARKS=Ylev
" plot the table "
YAXIS     3; MARKS=!(1...12); LABELS=Mlab
DSHADE    [WINDOW=3; KEY=0; YORIENT=reverse] Profitgroup; PEN=Pens
Updated on March 8, 2019

Was this article helpful?