console.clear();
// the two base colors
const guidanceColor = document.querySelector('#guidance_color');
const affordanceColor = document.querySelector('#affordance_color');
// background color of the whole panel for comparing against base colors
const outputColor = document.querySelector('#output_color');
// the grayscale ramp color inputs
const grayscaleButtons = document.querySelectorAll('#grayscaleRamp input');
// the opacity ramp percentage sliders
const opacitySliders = document.querySelectorAll('#opacityRamp input');
// canvas stuff
const canvas = document.createElement('canvas');
canvas.width = 10;
canvas.height = 10;
const ctx = canvas.getContext('2d');
// change these values to alter the default grayscale ramp
// these are the colors that are under the base color
const grayscaleRamp = {
50: '#F2F2F2',
100: '#E6E6E6',
200: '#CCCCCC',
300: '#B3B3B3',
400: '#999999',
500: '#808080',
600: '#666666',
700: '#4D4D4D',
800: '#333333',
900: '#1A1A1A'
};
// change these values to alter the default opacity ramp
// these values are applied to the black swatch that desaturates the base color
const opacityRamp = {
50: 0.9,
100: 0.8,
200: 0.7,
300: 0.35,
400: 0,
500: 0,
600: 0,
700: 0,
800: 0,
900: 0
};
let pickedColors = {};
// set grayscale button defaults from grayscaleRamp object
Object.entries(grayscaleRamp).forEach((entry, index) => {
grayscaleButtons[index].value = entry[1];
grayscaleButtons[index].nextElementSibling.innerText = entry[1];
});
// set opacity slider defaults from opacityRamp object
Object.entries(opacityRamp).forEach((entry, index) => {
opacitySliders[index].value = entry[1];
opacitySliders[index].nextElementSibling.innerText = entry[1];
});
// main function that creates/updates canvas and passes values to CSS variables
function setColors() {
// builds rgba string from pixel data passed from canvas
function getColor (imageData) {
return `rgba(${imageData.data[0]}, ${imageData.data[1]},...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.