cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <button id="startBtn">start</button>
<button id="stopBtn">stop</button>

<svg width="350" heigth="150" viewBox="0 0 350 150">
            <defs>

                <!-- EYE SHAPE -->
                <path
                    id="eyeShape"
                    d="
                        M 27,75
                        S 40 52 75 52
                        120 75 120 75
                        105 93 75 93
                        27 75 27 75 
                        z
                    "   
                />

                <symbol id="eye">
                    <use class="fillEye" xlink:href="#eyeShape"/>
                    
                    <g clip-path="url(#maskeye)">
                        <g id="irisPupil">
                            <ellipse id="iris" class="iris" cx="74" cy="72" rx="18" ry="22"  transform="translate(-23)"/>
                            <ellipse id="pupil" class="pupil" cx="74" cy="72" rx="6" ry="8"  transform="translate(-26)"  />   
                        </g>
                    </g>

                    <use class="strokeEye" xlink:href="#eyeShape"/>
                </symbol>


                <clipPath id="maskeye">
                    <use xlink:href="#eyeShape" />
                </clipPath>
            </defs>


            <use xlink:href="#eye"/>
            <use x="183" xlink:href="#eye" />
        </svg>
            
          
!
            
              body {
  background-color: #fff;
  margin: 20px;
  margin-top: 10px;
}

/* Eye */
svg {
  margin-top: 20px;
  display: block;
  background-color: #999;
  max-width: 100%;
  height: auto;
}
.fillEye {
  fill: #fff;
  stroke-width: 1px;
  stroke: #666;
}

.strokeEye {
  stroke: #333;
  stroke-width: 6px;
  fill: none;
  stroke-dasharray: 2px 5px;
}

.iris {
  fill: brown;
}

            
          
!
            
              const startBtn = document.getElementById("startBtn");
const stopBtn = document.getElementById("stopBtn");
// Calcul de la distance
const range = (min, max) => max - min;
// transformations
const transform = (progress, { start, end }) =>
  start + progress * range(start, end);
// timing functions
const tfn = {
  easeOutCubic: t => Math.pow(t - 1, 3) + 1,
  easeInCubic: t => Math.pow(t, 3),
  easeInQuad: t => t * t,
  easeOutQuad: t => t * (2 - t),
  parabolic: t => -4 * Math.pow(t, 2) + 4 * t
};

const animePupil = (function() {
  let rafID = null;
  let f = 0;
  let dir = 1;
  let replay;

  const NF = 40;
  const pupil = document.getElementById("pupil");
  const iris = document.getElementById("iris");

  const animDatas = {
    iris: {
      translateX: { start: -23, end: 23 },
      translateY: { start: 0, end: -7 },
      rx: { start: 18, end: 22 }
    },
    pupil: {
      translateX: { start: -26, end: 26 },
      translateY: { start: 0, end: -8 },
      rx: { start: 6, end: 8 }
    }
  };

  const frame = () => {
    f += dir;
    const progress = f / NF;
    const ease = dir - 1 ? tfn.easeInQuad(progress) : tfn.easeOutQuad(progress);
    const parabolic = tfn.parabolic(ease);

    console.log(parabolic);

    // Transform Iris
    iris.setAttribute(
      "transform",
      `translate(
                ${transform(ease, animDatas.iris.translateX)}
                ${transform(parabolic, animDatas.iris.translateY)}
            )`
    );
    iris.setAttribute("rx", transform(parabolic, animDatas.iris.rx));

    // Transform pupil
    pupil.setAttribute(
      "transform",
      `translate( 
                ${transform(ease, animDatas.pupil.translateX)}
                ${transform(parabolic, animDatas.pupil.translateY)}
            )`
    );
    pupil.setAttribute("rx", transform(parabolic, animDatas.pupil.rx));

    if (!(f % NF)) {
      dir *= -1;
      stop();
      replay = setTimeout(() => {
        play();
      }, 2500);

      return;
    }

    rafID = requestAnimationFrame(frame);
  };
  const play = () => {
    if (rafID) return;
    rafID = requestAnimationFrame(frame);
  };
  const stop = () => {
    clearTimeout(replay);
    cancelAnimationFrame(rafID);
    rafID = null;
  };
  return {
    play: play,
    stop: stop
  };
})();

startBtn.addEventListener(
  "click",
  () => {
    animePupil.play();
  },
  false
);

stopBtn.addEventListener(
  "click",
  () => {
    animePupil.stop();
  },
  false
);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console