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

              
                <div class="wrapper">
  <header>
    <h1>Sleeping Monk</h1>
  </header>
  <div class="monk-container">
    <div class="monk">
      <svg class="my-monk-body" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="100%" width="100%" version="1.1" id="Capa_1" viewBox="0 0 380.00 380.00" xml:space="preserve" transform="rotate(0)" stroke="currentColor" stroke-width="0.0038">
        <g id="bgCarrier" stroke-width="0" />
        <g id="tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="currentColor" stroke-width="2.2800000000000002" />
        <g id="iconCarrier">
          <g id="g309">
            <path style="fill-rule:evenodd;clip-rule:evenodd" d="M329.905,319.342c0,0-15.82-22.666-55.264-29.025 c8.627-7.418,16.863-14.328,24.899-21.48c8.654-7.727,11.936-16.977,8.332-28.564c-9.109-29.152-17.363-45.352-26.965-74.33 c-6.992-21.13-21.853-33.203-44.998-33.684c-4.307-0.086-8.872-0.844-12.799-2.506c-1.748-0.739-3.167-1.584-4.278-2.512 c-0.038-3.542,0.852-8.541,3.763-15.525c4.902-5.743,8.129-12.717,10.446-19.777c2.109-0.595,4.054-1.781,4.626-2.639 c2.231-3,6.363-6.777,7.913-10.275c3.161-7.846,0.297-11.859-1.19-13.049c-1.459-1.215-3.044-1.32-4.617-0.816 c0.437-1.481,0.898-2.95,1.444-4.398c5.604-14.83-1.742-29.617-16.232-36.921c-5.038-2.54-9.665-4.217-13.92-5.341 C209.89,8.093,200.91,0,190.001,0c-10.91,0-19.892,8.093-21.067,18.498c-4.255,1.124-8.882,2.801-13.921,5.341 c-14.488,7.304-21.834,22.091-16.231,36.921c0.546,1.448,1.009,2.918,1.445,4.4c-1.573-0.506-3.158-0.402-4.617,0.814 c-1.488,1.189-4.352,5.203-1.191,13.049c1.548,3.498,5.682,7.275,7.915,10.275c0.57,0.858,2.516,2.043,4.624,2.639 c2.132,6.495,5.034,12.919,9.302,18.379c0,0,4.287,8.332,6.622,15.096c-1.174,1.665-3.155,3.14-5.993,4.34 c-3.927,1.662-8.492,2.42-12.799,2.506c-23.144,0.48-38.006,12.554-44.998,33.684c-9.602,28.979-17.855,45.178-26.965,74.33 c-3.604,11.588-0.322,20.838,8.332,28.564c8.036,7.152,16.272,14.063,24.899,21.48c-39.443,6.359-55.264,29.025-55.264,29.025 C39.708,331.147,18.273,380,95.623,380h188.754C361.727,380,340.292,331.147,329.905,319.342z M130.92,270.641 c-7.604-3.676-20.056-18.707-18.714-24.473c4.927-14.504,10.925-25.434,18.714-39.496V270.641z M148.411,72.299 c-0.426-2.025-0.83-3.937-1.246-5.762c-1.682-7.358,1.066-16.242,7.538-24.363h70.592c6.475,8.121,9.224,17.005,7.539,24.363 c-0.415,1.825-0.819,3.736-1.246,5.762c-2.06,9.774-4.626,21.936-10.646,31.229c-6.81,10.505-16.93,15.612-30.94,15.612 c-14.014,0-24.135-5.107-30.942-15.612C153.038,94.234,150.472,82.072,148.411,72.299z M249.08,270.641v-63.969 c7.789,14.063,13.787,24.992,18.714,39.496C269.137,251.934,256.684,266.965,249.08,270.641z" id="path307" />
          </g>
        </g>
      </svg>
      <div class="my-monk-eye" id="left">
        <div class="pupil"></div>
      </div>
      <div class="my-monk-eye" id="right">
        <div class="pupil"></div>
      </div>
    </div>
  </div>
  <footer>
    <h2>Sources and Inspirations:</h2>
    <ul class="footer-container">
      <li><a href="https://www.svgrepo.com" target="_blank" rel="noopener noreferrer">SVG Icons by SVG Repo</a></li>
      <li><a href="https://www.svgrepo.com" target="_blank" rel="noopener noreferrer">SVG Icons by SVG Repo</a></li>
      <li><a href="https://web.dev/articles/css-trig-functions" target="_blank" rel="noopener noreferrer">Bramus' article of
          Trigonometric functions in CSS</a></li>
    </ul>
  </footer>
  <svg id="my-fly" fill="currentColor" height="40px" width="40px" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 205.041 205.041" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 205.041 205.041">
    <g id="SVGRepo_bgCarrier" stroke-width="0"></g>
    <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g>
    <g id="SVGRepo_iconCarrier">
      <path d="m198.969,60.373c-2.884-2.972-7.633-3.044-10.604-0.159l-29.809,28.927c-7.275-9.046-14.93-17.727-22.123-25.378l14.42-6.413c1.887-0.839 3.345-2.419 4.028-4.368l15.097-42.995c1.372-3.908-0.684-8.189-4.592-9.562-3.904-1.371-8.189,0.685-9.561,4.592l-14.025,39.942-1.46,.649c0.036-0.567 0.06-1.141 0.06-1.723 0-16.894-16.546-36.531-37.877-36.531-21.337,0-37.887,19.638-37.887,36.531 0,0.581 0.022,1.153 0.059,1.719l-1.451-.646-14.026-39.941c-1.371-3.908-5.653-5.961-9.561-4.592-3.908,1.372-5.964,5.653-4.592,9.562l15.097,42.995c0.684,1.948 2.142,3.529 4.028,4.368l14.419,6.413c-7.194,7.652-14.849,16.333-22.124,25.379l-29.808-28.928c-2.973-2.885-7.722-2.814-10.604,0.159-2.885,2.973-2.813,7.721 0.159,10.605l31.042,30.124c-19.331,26.319-32.612,53.26-20.392,65.483 3.287,3.286 7.607,4.699 12.606,4.699 6.113,0 13.244-2.12 20.744-5.507l10.162,33.914c0.974,3.25 3.954,5.349 7.182,5.349 0.713,0 1.438-0.102 2.155-0.317 3.968-1.189 6.221-5.37 5.032-9.337l-11.013-36.752c4.486-2.674 8.969-5.608 13.321-8.643 4.741,9.245 14.365,15.589 25.449,15.589s20.707-6.344 25.449-15.588c4.353,3.035 8.835,5.969 13.321,8.643l-11.013,36.751c-1.188,3.968 1.064,8.149 5.032,9.337 0.718,0.215 1.442,0.317 2.155,0.317 3.227,0 6.208-2.1 7.182-5.349l10.162-33.914c7.5,3.387 14.631,5.506 20.744,5.506 4.999,0 9.32-1.414 12.607-4.7 12.219-12.222-1.063-39.162-20.394-65.481l31.042-30.124c2.975-2.884 3.046-7.632 0.162-10.605zm-96.447-38.019c12.32,0 22.877,11.839 22.877,21.531 0,11.708-19.057,12.301-22.877,12.301-3.822,0-22.887-0.593-22.887-12.301 0.001-9.691 10.561-21.531 22.887-21.531zm-75.028,133.633c-0.829-1.074-1.436-9.219 10.757-29.452 4.085-6.779 9.063-14.014 14.767-21.498 0.067-0.083 0.132-0.168 0.195-0.252 6.14-8.04 13.119-16.363 20.718-24.714v53.72c-29.312,21.48-44.272,23.844-46.437,22.196zm75.026-5.407c-7.493,0-13.59-6.096-13.59-13.59v-67.233c4.114,0.935 8.665,1.429 13.592,1.429 4.926,0 9.475-0.495 13.588-1.429v67.233c1.42109e-14,7.494-6.096,13.59-13.59,13.59zm75.044,5.388c-2.183,1.666-17.145-0.7-46.454-22.175v-53.722c7.6,8.352 14.58,16.676 20.72,24.716 0.063,0.083 0.126,0.167 0.192,0.248 5.704,7.485 10.683,14.721 14.769,21.501 12.192,20.233 11.585,28.377 10.773,29.432z">
      </path>
    </g>
  </svg>
</div>
              
            
!

CSS

              
                *,
*:before,
*:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: "Nothing You Could Do", cursive;
}

:root {
  --monk-color: #f53900;
  --render-opacity: 0.5;
  --bg-daylight: linear-gradient(
    0deg,
    rgba(255, 167, 81, 1) 0%,
    rgba(255, 226, 89, 1) 100%
  );
  --bg-night: linear-gradient(
    0deg,
    rgba(153, 100, 49, 1) 0%,
    rgba(153, 136, 53, 1) 100%
  );
  --bg-opacity: 0;
  --bg-transition-duration: 0.5s;
  --going-to-sleep: 2000; /* in Milliseconds */
  --pupils-opacity: 0;
  --fly-opacity: 0;
  --fly-opacity-transition-duration: 0.5s;
  --fly-width: 20;
  --fly-height: 20;

  --pointer-x: 0;
  --pointer-y: 0;
  --my-x: 40;
  --my-y: 40;

  --eyesize: clamp(4px, 3.5vw, 26px);
  --eye-clip-path: ellipse(100% 5% at 0% 50%);
  --eye-right-rotate: rotate(180deg);
  --eye-bg-color: var(--monk-color);
  --eye-bg-transition-duration: 0.18s;

  /* Variables for calculation */
  --calculation: atan2(
    calc(
      var(--pointer-x) - var(--my-x) - (var(--fly-width) / 2) +
        var(--eye-correction-without-unit)
    ),
    calc(var(--pointer-y) - var(--my-y) - (var(--fly-height) / 2) + 0) * -1
  );
  --fly-x: calc(var(--my-x) * 1px);
  --fly-y: calc(var(--my-y) * 1px);
  --eye-correction: clamp(1px, 1vw, 80px);
  --eye-correction-without-unit: 0; /* => --eye-correction without units (for calculation purposes), set in javascript.js */
  --pupil-size: calc(var(--eyesize) / 2);
  --pupil-size-without-unit: 0;
  --pupilDegree: 0deg;
}

[data-theme="daylight"] {
  --old-bg-primary: linear-gradient(
    0deg,
    rgba(140, 120, 10, 1) 0%,
    rgba(251, 255, 0, 1) 100%
  );
  --bg-opacity: 1;
  --fly-opacity: 1;
  --fly-opacity-transition-duration: 0s;
  --render-opacity: 1;
  --pupils-opacity: var(--render-opacity);
  --eye-bg-color: white;
  --eye-clip-path: ellipse(100% 100% at 0% 50%);
  --eye-right-rotate: rotate(0deg);
  --eye-bg-transition-duration: 0s;
}

body {
  width: 100vw;
  height: 100svh;
}

.wrapper {
  display: grid;
  grid-template-rows: minmax(min-content, 12vw) 1fr min-content;
  overflow-x: clip;
  overflow-clip-margin: 40px;
  height: 100%;
  width: 100%;
  position: relative;
  background-image: var(--bg-night);
  z-index: 1;
  transition: background-image var(--bg-transition-duration) linear;
  container-type: inline-size;
  container-name: wrapper;

  & header {
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: var(--render-opacity);

    & h1 {
      padding: 2.5rem 1.5rem;
      font-size: clamp(1.8rem, calc(1rem + 2.5vw), 4.6rem);
      margin-top: calc(140px - 10vw);
      text-align: center;
      line-height: 1.12;
    }
  }

  & .monk-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;

    & .monk {
      width: min(600px, 80vw);
      position: relative;
      color: var(--monk-color);

      & .my-monk-body {
        width: 100%;
        height: 100%;
        opacity: var(--render-opacity);
        transition: opacity var(--fly-opacity-transition-duration) linear;
      }

      & .my-monk-eye {
        position: absolute;
        top: calc(14% + (var(--eyesize) / 2));
        right: calc(50% - (var(--eyesize) / 2));
        z-index: 10;
        background-color: var(--eye-bg-color);
        width: var(--eyesize);
        height: var(--eyesize);
        border-radius: 50%;
        clip-path: var(--eye-clip-path);
        transition: background-color var(--eye-bg-transition-duration) linear,
          clip-path var(--eye-bg-transition-duration) linear;

        &:nth-of-type(1) {
          translate: calc(var(--eyesize) * -1) calc(var(--eye-correction) * -1);
        }

        &:nth-of-type(2) {
          translate: calc(var(--eyesize) * 1) calc(var(--eye-correction) * -1);
          transform: var(--eye-right-rotate);
        }

        & .pupil {
          position: absolute;
          top: calc(var(--eyesize) / 2 - var(--pupil-size) / 2);
          left: calc(var(--eyesize) / 2 - var(--pupil-size) / 2);
          width: var(--pupil-size);
          height: var(--pupil-size);
          z-index: 20;
          border-radius: 50%;
          background-color: var(--monk-color);
          --multiplier: calc(var(--eyesize) - (var(--pupil-size) * 1.5));
          translate: calc(cos(var(--pupilDegree)) * var(--multiplier))
            calc(sin(var(--pupilDegree)) * var(--multiplier));
          opacity: var(--pupils-opacity);
        }
      }
    }
  }

  & #my-fly {
    position: absolute;
    width: clamp(8px, 7cqw, 40px);
    top: 0;
    left: 0;
    translate: var(--fly-x) var(--fly-y);
    color: black;
    rotate: var(--calculation);
    z-index: 10;
    transition: translate 0.2s linear;
    opacity: var(--fly-opacity);
    transition: opacity var(--fly-opacity-transition-duration) linear;
  }

  &::before {
    z-index: -1;
    position: absolute;
    content: "";
    background-image: var(--bg-daylight);
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    opacity: var(--bg-opacity);
    transition: opacity var(--bg-transition-duration) linear;
  }

  & footer {
    display: flex;
    flex-direction: column;
    container-type: inline-size;
    color: var(--monk-color);
    margin: 0 0.4rem 0.8rem;
    font-family: monospace, sans-serif;

    & h2 {
      font-size: 0.6rem;
      color: var(--monk-color);
      text-align: center;
      text-decoration: underline;
      margin-bottom: 0.5rem;
    }

    & .footer-container {
      font-size: 0.8rem;
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
      grid-template-rows: repeat(3, min-content);
      list-style-type: none;
      gap: 1rem;

      & li {
        display: flex;
        justify-content: center;
        align-items: center;
        flex-wrap: nowrap;

        & a {
          color: inherit;
          text-decoration: none;
          background-color: rgba(255, 255, 255, 0.5);
          transition: background-color 0.2s linear;
          padding: 0.4rem 0.8rem;
          border-radius: 10px;
          cursor: pointer;

          &:hover {
            background-color: rgba(255, 255, 255, 0.85);
          }
        }
      }
    }
  }
}

              
            
!

JS

              
                (() => {
  const $root = document.documentElement;
  const $body = document.body;
  const $myMonkEyes = document.querySelectorAll(".my-monk-eye");
  const $myFly = document.getElementById("my-fly");

  let timer;
  let moving = false;

  if ($root && $myMonkEyes && $myFly) {
    let {
      flyWidth,
      flyHeight,
      myMonkEyesCenterX,
      myMonkEyesCenterY
    } = updateSizes();
    const resizeObserver = new ResizeObserver(() => {
      ({
        flyWidth,
        flyHeight,
        myMonkEyesCenterX,
        myMonkEyesCenterY
      } = updateSizes()); /* Parantheses necessary bacause of destructuring existing variables */
    });
    resizeObserver.observe($body);

    $root.addEventListener("pointermove", (event) => {
      $root.setAttribute("data-theme", "daylight");
      if (timer) {
        clearTimeout(timer);
      }
      let x = event.clientX;
      let y = event.clientY;
      $root.style.setProperty("--pointer-x", Math.round(x).toString());
      $root.style.setProperty("--pointer-y", Math.round(y).toString());

      /**
       * Movement of the fly following the mouse is throttled by setTimeout.
       * Otherwise the fly would follow the mouse movement immediately.
       */
      if (!moving) {
        moving = true;

        setTimeout(() => {
          $root.style.setProperty("--my-x", Math.round(x).toString());
          $root.style.setProperty("--my-y", Math.round(y).toString());
          moving = false;
        }, 180);
      }

      /**
       * Pupils Movement
       */

      let { x: myFlyX, y: myFlyY } = $myFly.getBoundingClientRect();
      myFlyX += flyWidth / 2;
      myFlyY += flyHeight / 2;

      const calcPupilDegree = Math.atan2(
        myFlyX - myMonkEyesCenterX,
        (myFlyY - myMonkEyesCenterY) * -1
      );
      $root.style.setProperty(
        `--pupilDegree`,
        `${(calcPupilDegree * 180) / Math.PI - 90}deg`
      );

      /**
       * Sleeping Mode
       */

      timer = setTimeout(() => {
        $root.setAttribute("data-theme", "night");
      }, getComputedStyle($root).getPropertyValue("--going-to-sleep"));
    });
  }

  function updateSizes() {
    const {
      width: flyWidth,
      height: flyHeight
    } = $myFly.getBoundingClientRect();
    eyeCorrectionWithoutUnits =
      ($myMonkEyes[1].getBoundingClientRect().right -
        $myMonkEyes[0].getBoundingClientRect().x) /
      2;
    pupilSizeWithoutUnit =
      ($myMonkEyes[0].getBoundingClientRect().bottom -
        $myMonkEyes[0].getBoundingClientRect().y) /
      2;
    $root.style.setProperty("--fly-width", Math.round(flyWidth).toString());
    $root.style.setProperty("--fly-height", Math.round(flyHeight).toString());
    $root.style.setProperty(
      "--eye-correction-without-unit",
      eyeCorrectionWithoutUnits
    );
    $root.style.setProperty("--pupilSizeWithoutUnit", pupilSizeWithoutUnit);
    return {
      flyWidth,
      flyHeight,
      myMonkEyesCenterX: Math.round(
        ($myMonkEyes[0].getBoundingClientRect().x +
          $myMonkEyes[1].getBoundingClientRect().right) /
          2
      ),
      myMonkEyesCenterY: Math.round(
        ($myMonkEyes[0].getBoundingClientRect().y +
          $myMonkEyes[1].getBoundingClientRect().bottom) /
          2
      )
    };
  }
})();

              
            
!
999px

Console