--GriffinColorImpl.mesa
--Maureen Stone June 21, 1983 4:14 pm
DIRECTORY
Rope USING [ROPE, Equal],
GriffinColor,
ColorMap USING [SetHSVColor],
StyleDefs USING [Color];

GriffinColorImpl: PROGRAM
IMPORTS Rope, ColorMap
EXPORTS GriffinColor
= BEGIN
ColorPair: TYPE = RECORD[name: Rope.ROPE, value: StyleDefs.Color];
ColorTable: ARRAY[0..30) OF ColorPair ← [
[name: "black", value: [0,0,0]],
[name: "dk brown", value: [7,255,59]],
[name: "brown", value: [7,255,118]],
[name: "tan", value: [0,131,217]],
[name: "maroon", value: [234,255,79]],
[name: "dk red", value: [0,255,160]],
[name: "red", value: [0,255,255]],
[name: "orange", value: [10,255,255]],
[name: "dk yellow", value: [25,255,255]],
[name: "yellow", value: [40,255,255]],
[name: "lt yellow", value: [40,190,255]],
[name: "dk green", value: [71,255,59]],
[name: "green", value: [76,255,255]],
[name: "lt green", value: [71,193,255]],
[name: "dk blue", value: [150,255,170]],
[name: "blue", value: [148,255,255]],
[name: "lt blue", value: [141,150,255]],
[name: "dk aqua", value: [107,255,98]],
[name: "aqua", value: [107,224,255]],
[name: "cyan", value: [120,255,255]],
[name: "dk purple", value: [178,255,178]],
[name: "purple", value: [170,224,255]],
[name: "violet", value: [170,131,255]],
[name: "magenta", value: [200,255,255]],
[name: "pink", value: [206,170,255]],
[name: "dk grey", value: [0,0,40]],
[name: "grey", value: [0,0,120]],
[name: "lt grey", value: [0,0,200]],
[name: "pale grey", value: [0,0,230]],
[name: "white", value: [0,0,255]]
];
StringToColor: PUBLIC PROC [name: Rope.ROPE] RETURNS [color: StyleDefs.Color] = {
FOR i: INTEGER IN [0..LENGTH[ColorTable]) DO
IF Rope.Equal[name,ColorTable[i].name] THEN RETURN[ColorTable[i].value];
ENDLOOP;
ERROR;
};
ColorToString: PUBLIC PROCEDURE[color: StyleDefs.Color] RETURNS[Rope.ROPE] = {
FOR i: INTEGER IN [0..LENGTH[ColorTable]) DO
c: StyleDefs.Color ← ColorTable[i].value;
IF ABS[color.hue-c.hue] <5 AND ABS[color.saturation-c.saturation] <5
AND ABS[color.brightness-c.brightness] <5 THEN RETURN[ColorTable[i].name];
ENDLOOP;
RETURN["black"];
};
LoadColorMap: PUBLIC PROC = {
index: CARDINAL ← 100;
FOR i: INTEGER IN [0..LENGTH[ColorTable]) DO
c: StyleDefs.Color ← ColorTable[i].value;
ColorMap.SetHSVColor[index: index, h: c.hue/255.0, s: c.saturation/255.0, v: c.brightness/255.0];
index ← index+2;
ENDLOOP;
};
END.