So I'm trying to make a google spreadsheet that fills in each cell with a different colour, determined by RGB values I'll figure out later. End result will be that the sheet will be a color palette I can use elsewhere.
Problem is that I can't figure out how to make the function below (colorHex) apply the setBackgroundColor function on to the cell that it's currently running in.
I basically want to do =colorCell(254,108,72) into a cell, and that cell's background color changes into that color. So I'm sure this is a fairly simple question, but everytime I look up how to reference cells, I've yet to see an example that uses the cell the function is running in.
Help?
function colorCell(r,g,b) {
var colorCode = colorHex(decimalToHex(r,1), decimalToHex(g,1), decimalToHex(b,1));
// setBackgroundColor(colorCode); Where the magic will happen, hopefully
}
function decimalToHex(d, padding) {
var hex = Number(d).toString(16);
var hex = hex.toUpperCase();
padding = typeof (padding) === "undefined" || padding === null ? padding = 2 : padding;
while (hex.length < padding) {
hex = "0" + hex;
}
return hex;
}
function colorHex(r,g,b) {
var hexcode = "#";
var hexcode = hexcode.concat(r,g,b);
return hexcode;
}