RGBScript - MultiColors (aka more than 2)

Post Reply
FrozenTundraDJ
Posts: 15
Joined: Fri Sep 28, 2018 11:09 pm
Real Name: Austin Arbour

I've wanted to figure out a way to have more control over the colors when using the RGBScript feature.
I didn't want a static color and I didn't want to fade from one color to the next over the course of the steps.

I have created a few functions that can assist with this, only thing is you need to duplicate the script to implement the modifications.
I suggest you copy the .js file from the System Dir to the User Dir and rename it with the multicolor suffix.
See this page for more detail.

Code: Select all

Linux user dir: ~/.qlcplus/rgbscripts/
Linux system dir: /usr/share/qlcplus/rgbscripts/
OSX user dir: ~/Library/Application Support/QLC+/RGBScripts
OSX system dir: /Applications/QLC+.app/Contents/Resources/RGBScripts
Windows user dir: %HOMEPATH%\QLC+\RGBScripts
Windows system dir: C:\QLC+\RGBScripts
In a future version, I would like to look into the custom script properties and allow a user to:
  • Select from multiple color lists
  • Select random per step or per cycle
  • Define a custom color list array
  • Select to use the multicolor functions or the built-in color picker
You can manually configure the color list and select between the getRandomColorList and getRandomColor functions.
These should be swapped in the getColor and getNewColor functions as appropriate for your use case.
getRandomColorList - Allows you to get a color from the given array.
getRandomColor - Allows you to get a randomly generated color.

You can also select between the getColor and getNewColor functions.
These should be swapped in the main RGBScript function.
getColor - Returns the current color or if starting a new cycle will call one of the generator functions above to get a new color.
getNewColor - Returns a new color based on the above functions every time it is called.

Under the Copywrite notice, paste the following code.

Code: Select all

// List of colors to cycle through Hex format (RRGGBB)
// You can add as many colors as you wish.
// Use the following site for a list of sample colors.
// https://www.rapidtables.com/web/color/RGB_Color.html
const colorList = [
    "ff6666", // Salmon
    "ffb266", // Peach
    "ffff66", // Sun
    "b2ff66", // Lime
    "66ff66", // Green
    "66ffb2", // Turquoise
    "66ffff", // Sky
    "66b2ff", // Baby Blue
    "6666ff", // Dusk
    "b266ff", // Lavender
    "ff66ff", // Pink
    "ff66b2", // Lipstick
];

// Stores the current color selection for when only changing the color based on cycle
var currentColor = "";

// Returns a random color from the given list of colors
function getRandomColorList(colorArray) {
    return colorArray[~~(Math.random() * colorArray.length)];
};

// Returns a truly random color
function getRandomColor() {
    return Math.floor(Math.random() * 0xffffff).toString(16);
};

// Returns a color based on the current step
function getColor(step) {
    // Return the current color if not on the 1st step of the cycle
    if (step !== 0) {
        return currentColor;
    }

    // Generate a random color until the new color does not match the current color
    var oldColor = currentColor;
    while (oldColor === currentColor) {
        currentColor = getRandomColorList(colorList);
    }

    return currentColor;
};

// Returns a new random color every time it is called
function getNewColor() {
    var oldColor = currentColor;
    while (oldColor === currentColor) {
        currentColor = getRandomColorList(colorList);
    }

    return currentColor;
}
In the main RGBScript function we need to change a few things.
The line algo.name should be updated to differentiate from the original script, I usually use (Multicolor) as a suffix.
The line algo.acceptColors should be set to 0 as the given colors would be ignored and overridden by our functions.

algo.rgbMap is the function where the magic happens.
Usually at the top of the function I will add one of the following lines to override the given rgb color code.
Option 1

Code: Select all

rgb = parseInt(getColor(step), 16);
Option 2

Code: Select all

rgb = parseInt(getNewColor(), 16);
Yestalgia
Posts: 371
Joined: Thu Jun 17, 2021 9:31 am
Location: Australia
Real Name:
Contact:

I like this idea -thanks for sharing it.
Post Reply