Color scheme generator

컬러 스킴 생성기

The mechanism behind a "generate palette" button — pick a random base hue and a harmony rule (complementary, analogous, triadic…), then compute a fresh, coherent palette every time.

Also known as: Palette generator팔레트 생성기
···
html
<div class="wrap">
  <div class="head"><b>Generate</b><span class="tag" id="tag">Complementary</span></div>
  <div class="sws" id="sws"></div>
</div>
css
.wrap{width:min(480px,92%);display:grid;gap:clamp(8px,2.2vmin,14px)}
.head{display:flex;justify-content:space-between;align-items:center}
.head b{font:800 clamp(12px,3vmin,15px)/1 system-ui}
.tag{font:700 clamp(9px,2.4vmin,11px)/1 ui-monospace,monospace;padding:4px 10px;border-radius:999px;border:1px solid var(--line);color:var(--fg);background:var(--surface)}
.sws{display:grid;grid-template-columns:repeat(5,1fr);gap:6px}
.sws div{display:grid;gap:4px;justify-items:center}
.sws i{display:block;width:100%;aspect-ratio:1;border-radius:9px;border:1px solid var(--line)}
.sws b{font:700 clamp(7px,1.8vmin,9px)/1 ui-monospace,monospace;color:var(--muted)}
js
function hslToHex(h, s, l) {
  s /= 100; l /= 100;
  var k = function (n) { return (n + h / 30) % 12; };
  var a = s * Math.min(l, 1 - l);
  var f = function (n) { return l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1))); };
  var hex = function (x) { return Math.round(x * 255).toString(16).padStart(2, '0'); };
  return '#' + hex(f(0)) + hex(f(8)) + hex(f(4));
}
var RULES = [
  { name: 'Complementary', offsets: [0, 180, 0, 180, 90] },
  { name: 'Analogous', offsets: [-40, -20, 0, 20, 40] },
  { name: 'Triadic', offsets: [0, 120, 240, 60, 180] },
  { name: 'Split-Comp', offsets: [0, 150, 210, 75, 285] },
];
var sws = document.getElementById('sws'), tag = document.getElementById('tag');
sws.innerHTML = [0, 1, 2, 3, 4].map(function (i) { return '<div><i id="c' + i + '"></i><b id="t' + i + '"></b></div>'; }).join('');
var cells = [0, 1, 2, 3, 4].map(function (i) { return document.getElementById('c' + i); });
var labels = [0, 1, 2, 3, 4].map(function (i) { return document.getElementById('t' + i); });
function generate() {
  var rule = RULES[Math.floor(Math.random() * RULES.length)];
  var base = Math.floor(Math.random() * 360);
  var s = 62 + Math.random() * 20, l = 48 + Math.random() * 12;
  tag.textContent = rule.name;
  rule.offsets.forEach(function (off, i) {
    var h = (base + off + 360) % 360;
    var hex = hslToHex(h, s, Math.max(20, l - i * 3));
    cells[i].style.background = hex;
    labels[i].textContent = hex;
  });
}
generate();
setInterval(generate, 2600);

Most palette generators are not actually picking colors at random. Five random hues are unlikely to look good together, so the generator first picks a harmony rule at random — complementary at 180°, analogous within ±30°, triadic at 120° apart, split-complementary at 150°/210°, and so on — and only then applies that rule's fixed angles to a random base hue.

Randomness lives in exactly two places: the base hue and which rule gets used. The relationship between the colors — the angle — always comes from color theory, not chance. That is how a different palette every time can still feel deliberately coherent.

Real tools layer saturation and lightness variation, locking individual swatches, and accessibility checks on top of this, but the core algorithm is still those two steps: pick a rule, apply its angles.

When to use

Use it to generate a large batch of starting points quickly. A person still needs to review the final pick for contrast and meaning.