char2rgb

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Visualization
Introduced first in SolidGeometry 4.4, Creation date: 2018-11-26, Last change: 2025-09-14

returns a RGB value from a color character

Description

SG-Lib 4.5 supports list of colors

See Also: rgb2char , rgb2bgr16

Example Illustration

 missing image of char2rgb(c)

Syntax

rgb=char2rgb(c)

Input Parameter

c: color character

Output Parameter

rgb: [R G B] color

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

Output Results

Algorithm Steps

  1. Initialize a string colbar containing the characters 'kbgcrmyw', which represent the colors black, blue, green, cyan, red, magenta, yellow, and white, respectively.
  2. Iterate over each character in the input string ca.
  3. 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

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