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

Save Automatically?

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

              
                <div class="c c1"></div>
<div class="c c2"></div>
<!-- todo: make the gradient code exportable -->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Caveat");
:root {
  --h1: 315;
  --s1: 100;
  --l1: 50;
  --h2: 45;
  --s2: 100;
  --l2: 50;
  --l: 10;
  --t: 20;
  --toggle: "";
  --size: 35vmin;
  --g: radial-gradient(
    ellipse at calc(var(--l) * 1%) calc(var(--t) * 1%),
    hsl(var(--h1), calc(var(--s1) * 1%), calc(var(--l1) * 1%)),
    hsl(var(--h2), calc(var(--s2) * 1%), calc(var(--l2) * 1%))
  );
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Caveat, sans-serif;
  color: #fff;
  background: var(--g);
  overflow: hidden;
  font-size: 5vmin;
}

body::before {
  content: var(--toggle);
  position: absolute;
  top: 50%;
  left: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
  border: 0.65em solid rgba(255, 255, 255, 0.3);
  width: calc(var(--size) + 15vmin);
  height: calc(var(--size) + 15vmin);
  border-radius: 100%;
}

body::after {
  counter-reset: h1 var(--h1) s1 var(--s1) l1 var(--l1) h2 var(--h2) s2
    var(--s2) l2 var(--l2) l var(--l) t var(--t);
  content: "radial-gradient( ellipse at " counter(l) "% " counter(t) "%, hsl("
    counter(h1) ", " counter(s1) "%, " counter(l1) "%), hsl(" counter(h2) ", "
    counter(s2) "%, " counter(l2) "%) )";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: calc(0.3em + 0.7vmax);
  padding: 1em;
  background: rgba(0, 0, 0, 0.3);
  display: block;
  text-align: center;
}

.c {
  pointer-events: none;
  user-select: none;
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: var(--size);
  height: var(--size);
  will-change: transform;
}

.c::after {
  content: "";
  /*   counter(d); */
  pointer-events: auto;
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.15em;
  width: 2em;
  height: 2em;
  display: flex;
  flex-flow: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-radius: 100%;
  border: 0.25em solid;
  will-change: transform;
}

.c1 {
  transform: translate(-50%, -50%) rotate(calc(var(--h1) * 1deg));
}

.c1::after {
  counter-reset: d var(--h1);
  font-size: calc(var(--l1) * 0.01em + 0.15em);
  top: calc(var(--s1) * -0.2vmin);
  background: hsl(var(--h1), calc(var(--s1) * 1%), calc(var(--l1) * 1%));
}

.c2 {
  transform: translate(-50%, -50%) rotate(calc(var(--h2) * 1deg));
}

.c2::after {
  counter-reset: d var(--h2);
  font-size: calc(var(--l2) * 0.01em + 0.15em);
  top: calc(var(--s2) * -0.2vmin);
  background: hsl(var(--h2), calc(var(--s2) * 1%), calc(var(--l2) * 1%));
}

              
            
!

JS

              
                const style = document.documentElement.style;
const maxRadians = 6.283185307179586;
let toggle = "";
let delta = 50;

// see: http://jsfiddle.net/chriscoyier/t5Kts/
let distance = (wx, wy, mx, my) => {
  return Math.max(
    100,
    Math.min(
      200,
      Math.floor(Math.sqrt(Math.pow(mx - wx / 2, 2) + Math.pow(my - wy / 2, 2)))
    )
  );
};

let mathIt = (wx, wy, mx, my) => {
  let xp = Math.round((mx / wx) * 100);
  let yp = Math.round((my / wy) * 100);

  let rads = Math.atan2(my - wy / 2, mx - wx / 2);
  rads += maxRadians / 4;
  if (rads < 0) {
    rads += maxRadians;
  }

  let deg = Math.trunc(rads * (180 / Math.PI));
  let dist = distance(wx, wy, mx, my);

  if (toggle === "Color A") {
    style.setProperty("--h1", deg);
    style.setProperty("--s1", dist - 100);
  } else if (toggle === "Color B") {
    style.setProperty("--h2", deg);
    style.setProperty("--s2", dist - 100);
  } else if (toggle === "Centering") {
    style.setProperty("--l", xp);
    style.setProperty("--t", yp);
  }
};

let moreMath = (e) => {
  delta = Math.max(
    0,
    Math.min(100, delta + Math.max(-1, Math.min(1, e.wheelDelta || -e.detail)))
  );
  if (toggle === "Color A") {
    style.setProperty("--l1", delta);
  } else if (toggle === "Color B") {
    style.setProperty("--l2", delta);
  }
};

let textIt = (e) => {
  let css = Array.from(e.target.classList);
  if (css.includes("c1")) {
    toggle = toggle !== "" ? "" : "Color A";
  } else if (css.includes("c2")) {
    toggle = toggle !== "" ? "" : "Color B";
  } else {
    toggle = toggle !== "" ? "" : "Centering";
  }
  style.setProperty("--toggle", "'" + toggle + "'");
};

document.addEventListener("mousemove", (e) => {
  mathIt(window.innerWidth, window.innerHeight, e.clientX, e.clientY);
});

document.addEventListener("click", (e) => {
  textIt(e);
});

document.addEventListener("mousewheel", (e) => {
  moreMath(e);
});

              
            
!
999px

Console