Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- https://meodai.github.io/rampensau/ -->
<div class="header">
<h1>RampenSau</h1>
  <p>Dive into to <b>100% generative</b> okLCH color ramps! Need a fresh set? Hit the <b>N</b> key for a new set of 1000 colors.</p>
</div>
<main data-colors class="colors"></main>
<div class="footer">
<button aria-label="generate new colors" data-new>✦ New Colors</button>
<a href="https://github.com/meodai/rampensau" target="_blank">https://github.com/meodai/rampensau</a></div>

<div class="pannel">
  <div class="pannel__inner">
    <code class="codesample"><pre data-pre>generateColorRamp({
  "total": 3,
  "hStart": 58.01666832431667,
  "hCycles": 1.072090146588653,
  "sRange": [
    0.4049462928696227,
    0.6203349874762167
  ],
  "lRange": [
    0.18867952758807185,
    0.9951370932190609
  ]
})</pre></code>
  </div>
</div>
              
            
!

CSS

              
                
body {
  font-family: 'Bricolage Grotesque', sans-serif;
  background: #202126;
  color: #fff;
  padding: 4rem;
  font-size: 3vmin;
}

.colors {
  display: flex;
  flex-wrap: wrap;
  gap: 2vmin;
  align-items: center;
  justify-content: center;
  max-width: 60rem;
  margin: 0 auto;
}

.palette {
  position: relative;
  aspect-ratio: 2;
  flex: 1 1 20%;
  min-width: 6rem;
  background: var(--crnd);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: .3rem;
  &::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(90deg, var(--gc));
    transform: translateY(min(1vw, 4px));
    border-radius: .3rem;
  }
  &::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: .3rem;
    filter: blur(30px);
  }
  &:hover {
    background: linear-gradient(60deg, var(--gs));
    box-shadow: inset 0 0 0 min(0.3vw, 2px) var(--c4),
                inset 0 0 0 min(0.5vw, 4px) var(--c0);
    > * {
      display: none;
    }
    &::after {
      background: var(--c4);
    }
  }
}

.palette__swatch {
  width: 20%;
  aspect-ratio: 1;
  background: var(--color);
  border-radius: 50%;
  margin-left: -8%;
  position: relative;
  left: 1vw;
  box-shadow: 0 0 0 min(0.3vw, 2px) var(--c0),
              min(-0.2vw, -2px) 0 0 max(0.3vw, 3px) var(--color);

}

.palette--1 .palette__swatch {
  border-radius: 0%;
  transform: rotate(45deg) scale(.8);
  box-shadow: 0 0 0 min(0.3vw, 2px) var(--c0),
              0 0 0 max(0.4vw, 4px) var(--color);
}

.palette--2 {
  --dotSize: 0.2vw;
  --bgSize: 1.2vw;
  --bgPosition: calc(var(--bgSize) / 2);

  background-image: radial-gradient(
      circle at center,
      var(--crnd2) var(--dotSize),
      transparent 0
    ), radial-gradient(circle at center, var(--crnd2) var(--dotSize), transparent 0);
  background-size: var(--bgSize) var(--bgSize);
  background-position: 0 0, var(--bgPosition) var(--bgPosition);
}

.palette--3 {
  /*background: linear-gradient(-90deg, var(--gc));
  background-size: 150% 100%;
  background-position: 25% 0;*/
  .palette__swatch {
    background: var(--color);
    border-radius: 0;
    box-shadow: 0 0 0 min(0.3vw, 2px) var(--c0);
  }
}



.palette code {
  display: none;
}


h1 {
  margin-top: .4rem;
  width: 100%;
  font-size: 10vw;
  font-weight: 900;
  letter-spacing: -0.01em;
}

p {
  font-size: 1.2em;
  max-width: 30ch;
  line-height: 1.3;
  margin-top: 4em;
  margin-bottom: 1em;
}

b {
  font-weight: 900;
}

button {
  border-radius: .3rem;
  
  background: #fff;
  color: #202126;
  font-size: 1.4rem;
  padding: .5em .7em .45em;
  line-height: 1;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
  transform-origin: 0 50%;
}

.header {
  max-width: 60rem;
  margin: 2em auto 4rem;
}


.footer {
  display: flex;
  margin: 2em auto 4rem;
  max-width: 60rem;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.codesample {
  font-size: .6em;
}

.pannel {
  left: 0;
  right: 0;
  bottom: 0;
  position: sticky;
  background: #fff;
  transform: translateY(0%);
  display: none;
}

.pannel__inner {
  max-width: 60rem;
  margin: 0 auto;
  padding: 2rem 0;
}

@media (prefers-color-scheme: light) {
  body {
    background: #fff;
    color: #202126;
  }
  button {
    background: #202126;
    color: #fff;
  }
}

              
            
!

JS

              
                console.clear();

// currated generateColorRamp options for RampenSau
// fine-time them here until you like it: https://meodai.github.io/rampensau/
const newOptions = () => ({
  total: 2 + Math.round(Math.random() * 4),
  hStart: Math.random() * 360,
  hCycles: -1.25 + Math.random() * 2.5,
  sRange: [
    .2 + Math.random() * .4, 
    .25 + Math.random() * .7
  ],
  sEasing: x => Math.pow(x, 2),
  lRange: [
    Math.random() * .4, 
    Math.random() < .5 ? // half of the palettes will become pretty bright
    .65 + Math.random() * .35 : 
    .98 + Math.random() * .02,
  ],
  lEasing: x => Math.pow(x, 1.25),
});

const createPalette = ({cMod = 1, mode = 'oklch'} = {}) => {
  // invoke the function with the random options
  const options = newOptions();
  const colors = rampensau.generateColorRamp(options);
  
  let cssColors;
  // sometimes we want oklch colors sometimes hsl, why you ask? Because we can
  if ( mode === 'oklch' ) {
    // turn the array returned by RampenSau into something your browser understands
    cssColors = colors.map(color => `oklch(${color[2]} ${color[1] * cMod * 100}% ${color[0]})`);
  } else if ( mode === 'hsl') {
    cssColors = colors.map(color => `hsl(${color[0]} ${color[1] * cMod * 100}% ${color[2] * 100}%)`);
  }
  
  const $code = document.createElement('code');
  $code.innerHTML = `generateColorRamp(${JSON.stringify(options, null, 2)}).map(c =>
    ${mode === 'oklch' ? '"oklch(${c[2]} ${c[1] * ' + (cMod * 100) + '}% ${c[0]})"' : '"hsl(${c[0]} ${c[1] * ' + cMod * 100 + '}% ${c[2] * 100}%)"'}
  )`;
  

  // build the little sample HTML color things
  const $w = document.createElement('div');
  $w.appendChild($code);
  
  $w.classList.add(`palette--${~~(Math.random() * 5)}`);
  $w.classList.add('palette');
  $w.style.setProperty('--gc', cssColors.join());
  $w.style.setProperty('--gs', cssColors.map((c,i) => `${c} ${(i/colors.length) * 100}%, ${c} ${(i+1)/colors.length * 100}%`).join());
  $w.style.setProperty('--crnd', cssColors[~~(cssColors.length * Math.random())]);
  $w.style.setProperty('--crnd2', cssColors[~~(cssColors.length * Math.random())]);
  
  $w.dataset.cls = cssColors.join();
  
  cssColors.forEach((color, i) => {
    $w.style.setProperty(`--c${i}`, color);
    
    const $swatch = document.createElement('div');
    
    $swatch.style.setProperty(`--ri`, i/(cssColors.length - 1));
    $swatch.classList.add('palette__swatch');
    $swatch.style.setProperty('--color', color);

    $w.appendChild($swatch);
  });
  
  return $w;
}

const $b = document.querySelector('[data-colors]');

const np = () => {
  $b.innerHTML = '';
  new Array(1000).fill(0).forEach(_ => {
    $b.appendChild(createPalette(
      {
        // randomly clamp the chroma / saturation half ot the time
        cMod: Math.random() < .5 ? 1 : .5 * Math.random() + .5,
        // 10% will be hsl the others oklch
        mode: Math.random() < .1 ? 'hsl' : 'oklch',
      }
    ))
  })
}

np();

document.documentElement.addEventListener('click', e => {
  const $t = e.target; 
  if ( $t.matches('.palette') ) {
    console.log( $t.querySelector('code').innerHTML )
    logColors( $t.dataset.cls.split(',') );
  }
});

document.querySelector('[data-new]').addEventListener('click', np);

document.addEventListener('keyup', event => {
  if (event.key === 'n') {
    np()
  }
});

function logColors (colors) {
  let c, o = "",
    s = [];
  for (c of colors) {
    o += `%c ✦`,
    s.push(`background: ${c}; color: ${c}`);
  }
  console.log(o, ...s);
};
              
            
!
999px

Console