Hello
Is there a command to take a variable string value ("Blue") to be use in a color definition.
Martin
String to color number
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: String to color numver
Not that I'm aware of.Is there a command to take a variable string value ("Blue") to be use in a color definition.
Btw, the reserved word Blue is a constant for the RGB value for the colour blue. Little tip: make a function that has the colour name as input, then uses a switch statement to return the RGB colour for that name.
As a starting point (needs to be tested and expanded on), the function named "NameToColour":
Code: Select all
Inputs:
ColourName(StringSimple);
Variables:
colourInLowerString(""); // not case-sensitive anymore
colourInLowerString = LowerStr(ColourName);
switch (colourInLowerString ) begin
case "blue":
NameToColour = RGB(0, 0, 255);
case "black":
NameToColour = RGB(0, 0, 0);
end;
Code: Select all
SetPlotColor(1, NameToColour("black"));
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: String to color numver
Hello
Is there a command to take a variable string value ("Blue") to be use in a color definition.
Martin
Code: Select all
if mystring = "Blue" then color = blue;
if mystring = "Red" then color = red;
if mystring = "Green" then color = green;
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: String to color numver
Yes, they're listed here. Btw, there are a lot of other pretty colours (see here) that you could use in case you want more than one type of green or blue.If I recall, there is 17 reserved word for color, I will need to reference each of them. Dull to do, but possible.