Gets the name of the nearest colour to an RGB colour (D.B. Baird & R.W. Payne).
No Options
Parameters
RGB = scalars or variates |
RGB values |
NAME = texts |
Names of nearest colours |
EXACT = scalars or variates |
Indicates whether or not the colour name is an exact match to the RGB value |
Description
Colours on a computer can be defined by their RGB values. These define the intensities of the red, green and blue components that are combined to form the colour. Many colours can also be defined by standard names, such as Crimson, Gold, Olive or Turquoise; for the full list see PEN. The names may be clearer and more convenient to use than the RGB values. Sometimes, however, only the RGB values may be available as, for example, when IMPORT reads background colours from Excel.
This procedure, therefore, provides a way of matching RGB values to the closest named colour. The RGB values are provided by the RGB parameter, in either a scalar or a variate, and the NAME parameter saves a text containing the names. The EXACT parameter can save a scalar or a text (according to the type of the RGB parameter) that contains one if the name is an exact match or zero otherwise.
Options: None
Parameters: RGB, NAME, EXACT.
Action with RESTRICT
Restrictions are ignored.
See Also
Directive: PEN.
Procedures: DCOLOURS, DSCOLOURS, GETRGB.
Functions: BLUE, GRAY, GREY, GREEN, RED, RGB.
Commands for: Graphics.
Example
CAPTION 'RGBNAME example'; STYLE=major
CAPTION 'Display colour names for Genstat default colours'; STYLE=minor
PEN 1...17; SAVE=PS[1...17]
VARIATE [VALUES=PS[]['colour']] Std_RGB
RGBNAME Std_RGB; Std_Colours
PRINT Std_Colours; JUST=left
CAPTION 'Generate some random colour names'; STYLE=minor
CALC RGB = RGB('white')*URAND(662355;20)
RGBNAME RGB; Colours
PRINT Colours; JUST=left
CAPTION !t('Excel file with data set from a variety trial,',\
'where background cell colours indicate outliers and harvest date');\
STYLE=minor
"Read data ignoring top row containing trial description"
IMPORT [PRINT=*] '%DATA%/SouthlandBarley.xlsx'; CELL='A2'; ISAVE=pData
" Read RGB background colours from last two columns
(yellow colours indicate harvest week 2, and red
colours mark plots affected by header malfunction) "
IMPORT [PRINT=*; XLSXCONTENT=backcolour] '%DATA%/SouthlandBarley.xlsx';\
CELL='L3:M'; COLUMNS=!T('WeekRGB','YieldRGB')
" Convert RGB values to colour names
and show where the reds and yellows occur "
RGBNAME WeekRGB,YieldRGB; WeekColour,YieldColour
PRINT Plot,Row,WeekColour,Yield,YieldColour; FIELD=2(6),10,8,10; \
DECIMALS=2(0),*,2,*; JUST=2(right),left,right,left
"Fit best spatial model to full dataset ignoring outliers and harvest date"
VAROWCOLUMNDESIGN [ROWS=Row; COLUMNS=Column; REPLICATES=Rep; \
FIXED=Entry; PLOTFACTOR=Plot; PRINT=best; \
PBEST=model,components,Waldtests,means; MVINCLUDE=yvariate; \
VCONSTRAINTS=positive; RSTRATEGY=optimal; TRYSPATIAL=always] Yield
VPLOT [TITLE='Yield including outliers']
" Remove outliers marked with red "
CALC Yield = MVINSERT(Yield; YieldColour .in. 'Red')
"Create variable indicating week of harvest (week 2 marked with yellow)"
CALC Week2 = WeekColour .in. 'Yellow'
"Fit best spatial model, removing outliers including effect of harvest date "
VAROWCOLUMNDESIGN [ROWS=Row; COLUMNS=Column; REPLICATES=Rep; \
FIXED=Entry + Week2; PLOTFACTOR=Plot; PRINT=best; \
PBEST=model,components,Waldtests,means; MVINCLUDE=yvariate; \
VCONSTRAINTS=positive; RSTRATEGY=optimal; TRYSPATIAL=always] Yield
VPLOT [TITLE='Yield adjusted for harvest date excluding outliers']