// Function to set the color from RGB value strings void setColorByRgb(string inR, string inG, string inB){ // Set values in the RED/GREEN/BLUE fields setRgbField(inR, inG, inB); // Check if the input values are valid integers if( isInt(inR) && isInt(inG) && isInt(inB) ){ // Convert to int int r = inR; int g = inG; int b = inB; // Check if the values are within valid RGB range if(0<=r&&r<=255 && 0<=g&&g<=255 && 0<=b&&b<=255){ // Create a color array int color[] = {r, g, b, 255}; // Apply the color to the display panel setDisplayColor(color); // Get the color code string code = hex( getColorCode(color) ); code = formatColorCode(code); // Set value in the CODE field setCodeField(code); }else{ alert("RED / GREEN / BLUE values must be in the range of 0 to 255."); } }else{ alert("RED / GREEN / BLUE values must be integers."); } } // Function to convert hex string with "0x" prefix into 6-digit color code format // (called from setColorByRgb) string formatColorCode(string code){ // Get original string length int length = countText(code); // Remove the "0x" prefix code = cropText(code, 2, length); length -= 2; // Calculate how many leading zeros are needed int zeros = 6 - length; // Pad the beginning with zeros to make it 6 digits for(int i=0; i