// Function to create a color wheel on a canvas element
function createColorWheel(config) {
// Retrieve canvas and context
const canvas = document.getElementById(config.canvasId);
const ctx = canvas.getContext('2d');
// Calculate center and radii of the color wheel
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const outerRadius = (canvas.width - 2) / 2;
const innerRadius = outerRadius - config.trackWidth;
const dragCircleRadius = Math.round(config.trackWidth / 3);
const dragCircleOffset = (config.trackWidth / 2) - dragCircleRadius;
const dragCirclePosition = outerRadius - dragCircleRadius - dragCircleOffset;
let dragCircleAngle = 0; // Initial angle of the draggable circle
let isDragging = false; // Flag to track if mouse is being dragged
let lightness = config.initialLightness; // Initial lightness value
let saturation = config.initialSaturation; // Initial saturation value
let whitePointsHSL = []; // Array to store HSL values for the white points
// Function to calculate the positions of white circles based on the palette type
function calculatePalettePositions(angle, paletteType) {
const positions = [];
switch (paletteType) {
case 'analogous':
positions.push(angle - 30, angle + 30);
break;
case 'complementary':
positions.push(angle + 180);
break;
case 'triadic':
positions.push(angle + 120, angle + 240);
break;
// Add more cases for other palette types as needed
default:
break;
}
return positions;
}
// Function to draw the color wheel and update palette
function draw() {
whitePointsHSL = [];
ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear canvas
// Draw color wheel
for (let angle = 0; angle < 360; angle++) {
let gradient = `hsl(${angle}, ${saturation}%, ${lightness}%)`;
ctx.beginPath();
ctx.moveTo(centerX, centerY);
ctx.arc(centerX, centerY,...
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.