Syntax
rgb=char2rgb(c)
Input Parameter
Output Parameter
Examples
char2rgb('r')
char2rgb('krgbw')
Copyright 2018-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, char2rgb
, converts a color character or a string of color characters into their corresponding RGB values. It is part of the SG-Library and was introduced in SolidGeometry 4.4.
Input Parameters
- ca: A string of color characters. Each character represents a color.
Output Results
- rgb: An array of RGB values corresponding to the input color characters.
Algorithm Steps
- Initialize a string
colbar
containing the characters 'kbgcrmyw', which represent the colors black, blue, green, cyan, red, magenta, yellow, and white, respectively.
- Iterate over each character in the input string
ca
.
- For each character
c
in ca
:
- Find the index of
c
in colbar
using strfind
. Subtract 1 to get a zero-based index.
- Convert the index to a binary string of length 3 using
dec2bin
.
- Convert each binary digit to a double, multiply by 255, and store the result in the
rgb
array.
Example Usage
char2rgb('r')
returns the RGB value for red.
char2rgb('krgbw')
returns the RGB values for black, red, green, blue, and white.
Algorithm explaination created using ChatGPT on 2025-08-18 23:12. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21