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 id="look-at-snow" width="600" height="540" viewBox="0 0 600 540">
            <defs>


                <!-- SNOWFLAKE -->
                <symbol class="snowflake" id="snowflake" width="20" height="23">
                    <path fill="none" d="M15 4.8v3.8l3.31 1.9m.78-2.4l-1.6-.93V5.33m-4.42 4.4l6.02-3.48m-.78 6.23l-3.3 1.91v3.82m2.47-.54v-1.85l1.6-.93m-6.01-1.62l6.02 3.48m-5.78 2.44L10 17.28l-3.3 1.9m1.7 1.89l1.6-.93 1.6.93M10 15.04V22m-5-3.78V14.4l-3.31-1.9m-.78 2.4l1.6.93v1.85m4.42-4.4L.91 16.75m.78-6.23l3.3-1.91V4.79m-2.47.54v1.85l-1.6.93m6.01 1.62L.91 6.25M6.7 3.81L10 5.72l3.3-1.9m-1.7-1.89l-1.6.93-1.6-.93M10 7.96V1m0 14.03l-3.07-1.77V9.73L10 7.96l3.07 1.77v3.54z" />
                </symbol>

                <filter id="blur1">
                    <feGaussianBlur stdDeviation=".6" />
                </filter>
                <filter id="blur2">
                    <feGaussianBlur stdDeviation="1.2" />
                </filter>
                <filter id="blur3">
                    <feGaussianBlur stdDeviation="2" />
                </filter>


                <!-- Hair -->
                <pattern patternUnits="userSpaceOnUse" id="hairpattern" width="30" height="30" x="0" y="0"> 
                    <circle fill="#000" cx="15" cy="15" r="7.5" filter="url(#blur1)"/>
                </pattern>
                <pattern id="hairpattern1" xlink:href="#hairpattern" patternTransform="rotate(30)"></pattern>
                <pattern id="hairpattern2" xlink:href="#hairpattern" patternTransform="rotate(10)"></pattern>
                <pattern id="hairpattern3" xlink:href="#hairpattern" patternTransform="rotate(20)"></pattern>

                <path id="hair-path" d="M334 66c-124 0-189 81-206 194-4 24-6 54-5 87 41-36 82-126 82-126s73 20 122 24 149 4 149 4 9 133 37 170c13-36 22-71 27-99 18-122-27-236-173-252l-33-2z"/>


                <!-- EYE SHAPE -->
                <path
                    id="eyeShape"
                    class="eyeShape"
                    d="
                        M 27,75
                        S 40 52 75 52
                        120 75 120 75
                        105 93 75 93
                        27 75 27 75 
                        z
                    "   
                    />
                
                <radialGradient id="irisGradient">
                    <stop offset="60%" stop-color="hsl(15, 50%, 32%)" />
                    <stop offset="90%" stop-color="hsl(10, 40%, 20%)" />
                </radialGradient>

                <!-- EYE -->
                <symbol id="eye">
                    <!-- <use class="fillEye" xlink:href="#eyeShape"/> -->
                    <path class="fillEye eyeShape" d="M 27,75 S 40 52 75 52 120 75 120 75 105 93 75 93 27 75 27 75 z "/>
                    
                    <g clip-path="url(#maskeye)">
                        <g>                            
                            <ellipse id="iris" class="iris" cx="74" cy="72" rx="18" ry="22" transform="translate(-20 -4)" />
                            <ellipse id="pupil" class="pupil" cx="74" cy="72" rx="6" ry="8" transform="translate(-22 -5)" />   
                        </g>

                        <circle class="glint" cx="90" cy="65" r="6" filter="url(#blur2)" />
                    </g>

                    <!-- <use class="strokeEye" xlink:href="#eyeShape"/> -->
                    <path class="strokeEye eyeShape" d="M 27,75 S 40 52 75 52 120 75 120 75 105 93 75 93 27 75 27 75 z "/> </symbol>>
                </symbol>


                <clipPath id="maskeye">
                    <use xlink:href="#eyeShape" />
                </clipPath>
            </defs>
            
            <g id="face">
                <path class="skin"
                    d="M530 328c-17 119-122 358-257 339-135-18-156-279-139-398 18-119 90-202 230-187 141 16 184 126 166 246z"
                />
                <path class="skin-light" filter="url(#blur3)"
                    d="M198 312c32 12 64 6 79-10 15-15 42-48 32-73-11-25-70-70-103-45s-44 64-36 89c9 26 17 32 28 39zm267-114c-32-13-65-6-80 9-16 16-43 50-32 75 10 26 71 71 104 46 33-26 45-65 36-91-8-26-17-32-28-39zM156 336c-13 14-22 43-18 89 4 45 6 65 33 99 17 22 31 29 36 29 3 0 21-31 29-39 8-6 24-9 23-2s-28 18-26 30c4 2 10-2 17 0 8 2 23 10 31 10 14 1 38-2 43 1 8 4 8 14 8 14s6-11 1-16c-4-5-21-5-23-8-2-4-6-12 2-12 7 1 16-1 18-2 3-1 20 2 21 10s-5 23 0 29c5 5 19 19 32 18 13 0 48-20 59-32 6-6 30-61 38-88 10-42-7-66-15-68 2 0 5 35-19 51-7 4 18 9 18 17 0 7-3 25-19 21-20-4-23 10-24 14 0 3-16 7-21 13-2 9-7 16-11 17-5 1-22-8-31-13-30-13-34-72-58-72-12 0-28 31-43 43-5 3-18-2-27 1-8 2-23 9-31 8-14-2-31-20-31-31 0-12 10-18 3-22-7-3-21 0-23-13s26-25 24-26c-2-2-22-6-17-16 20-2 38-14 30-24l-29-30z"
                />
                <path class="skin-dark" filter="url(#blur2)"
                    d="M343 484s7 17 27 30c11-3 11-11 11-11s-29-17-38-19zm-97-17s-8 30-57 10c28 0 37-13 57-10zm81-69c8-8 23-12 35-12 13 1 60 18 73 29 14 11 14 18 10 18-14 2-37-12-47-13l-45-6c-4 0-16 2-27-5-1-3 1-11 1-11zm-143-5c9-4 59 5 86 17 5 4 10 3 14-12-2-5-23-18-40-21-14-3-44-7-58-2-7 5-2 18-2 18zm118 166c4-2 4-6 12-5 7 2 11 6 10 8-1 3-7 3-13 2-7 0-7-3-9-5zm-61-10c6 3 13 10 17 11 4 5 16 9 16 7-1-2-13-16-21-21-10-1-12 3-12 3zm97-105c5-7 7-17 33-15s39 5 50 17c12 11 21 21 22 31-4 2-13 0-16-2-2-1-14-14-31-23-25-13-43 8-44 9-10-5-19-5-14-17zm-166-10c5-3 21-11 37-10 20 0 28 13 35 17s19 4 21 0c4-1-11-18-24-25-32-15-74-4-78 5-3 9-2 15 9 13z"
                />

                <use xlink:href="#hair-path" fill="url(#hairpattern1)" />
                <use xlink:href="#hair-path" fill="url(#hairpattern2)" />
                <use xlink:href="#hair-path" fill="url(#hairpattern3)" />

            
                <g transform="rotate(9.3) translate(208, 332)">
                    <!-- <use x="115" y="350" xlink:href="#eye"/> -->
                    <!-- <use x="320" y="350" xlink:href="#eye" /> -->
                    <use x="0" xlink:href="#eye" transform="skewX(3)" />
                    <use x="183" xlink:href="#eye" transform="skewX(-3)"/>
                </g>
            </g>
        </svg>
            
          
!
            
              body {
  background-color: #fff;
  margin: 30px;
  margin-top: 10px;
}

/* Eye */
svg {
  margin-top: 20px;
  display: block;
  background: linear-gradient(
    to bottom,
    hsl(240, 40%, 60%) 0,
    hsl(240, 50%, 15%) 100%
  );

  max-width: 100%;
  height: auto;
}

.skin {
  fill: hsl(43, 15%, 19%);
}
.skin-light {
  fill: hsla(0, 0%, 100%, 0.1);
}
.skin-dark {
  fill: hsla(0, 0%, 0%, 0.4);
}
.fillEye {
  fill: #ddd;
  stroke-width: 1px;
  stroke: #333;
}

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

.iris {
  /* fill: brown; */
  fill: url(#irisGradient);
}

.glint {
  fill: hsla(0, 0%, 100%, 0.5);
}

.snowflake {
  fill: none;
  stroke: #fff;
  /* stroke:  red; */
  /* stroke-width: 1px; */
}

            
          
!
            
              
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
const svg = document.getElementById('look-at-snow');
svg.w = svg.getAttribute('width');
svg.h = svg.getAttribute('height');

// Calcul de la distance
const range = (min, max) => max - min;
// Random
const random = (min, max) => Math.random() * (max - min) + 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;
    let max;
    
    const NF = 40;
    const pupil = document.getElementById('pupil');
    const iris = document.getElementById('iris');
    const face = document.getElementById('face');


    const maxRandom = () => {
        max = Math.round( Math.random() * NF );
    };

    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 }
        },
        face: {
            rotate: { start: -4, end: -1 }
        }   
    };
        
    const frame = () => {
        f += dir;
        const progress = f/NF;
        // const ease = (dir-1) ? tfn.easeInCubic(progress) : tfn.easeOutCubic(progress);
        const ease = progress;
        const easeInquad = tfn.easeInQuad(progress);
        const parabolic = tfn.parabolic(ease);

        // 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)
        );
        // Transform face
        face.setAttribute(
            'transform', 
            `rotate( 
                ${transform(easeInquad, animDatas.face.rotate)} 300 600
            )`
        );


        if ( f === max || !(f%NF) ) {
            dir *= -1;
            stop();
            replay = setTimeout( () => {
                play(); 
            }, random(2000, 4500));
            return;
        }

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

const animeEyelids = (function(){
    let rafID = null;
    let f = 0;
    let replay;
    
    const NF = 20;
    const eyeLids = document.querySelectorAll('.eyeShape');
    // Path coordinates
    const animDatas = {
        open :  [40, 52, 75, 52, 120, 75, 120, 75, 105, 93, 75, 93, 27, 75, 27, 75],
        close : [40, 93, 75, 93, 120, 75, 120, 75, 105, 93, 75, 93, 27, 75, 27, 75]
    };

    const frame = () => {
        f += 1;
        const progress = f/NF;
        const parabolic = tfn.parabolic(progress);

        const path = animDatas.open.map((start, index) => {
            const datas = {
                start : start,
                end: animDatas.close[index]
            };
            const point = transform(parabolic, datas);
            return point;
        });

        // eyeLids.setAttribute('d', `M 27 75 S ${path.join(' ')} z`);
        Array.prototype.forEach.call(eyeLids, function(el){
            el.setAttribute('d', 'M 27 75 S ' + path.join(' ') + ' z');
        });



        if (!(f%NF)) {
            stop();
            replay = setTimeout( () => {
                play(); 
            }, random(1500, 10000));
            return;
        }

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

// snowflake animation
const animeSnow = (function(){

    let rafID = null;

    const randomInterval = (callback, min, max) => {
        let NF = Math.round(random(min, max));
        let f = 0;

        const frame = () => {
            f += 1;
            if (f >= NF) {
                NF = random(min, max);
                f = 0;
                callback();
            }
            rafID = requestAnimationFrame(frame);
        };
        rafID = requestAnimationFrame(frame);
    };

    const newFlake = () => {
        // console.log('create new flake');
        const flake = document.createElementNS('http://www.w3.org/2000/svg', 'use');
        flake.setAttributeNS('http://www.w3.org/1999/xlink', 'href', '#snowflake');

        // Apply a easeInQuad function in Math.rand
        // For more small than greater
        const rand = Math.random();
        const easeRand = tfn.easeInQuad(rand);
        const scaleFactor = easeRand * (4 - 1) + 1;

        // Difine a SVG Blur filter acording to the scaleFactor
        let blurFactor = 0;
        if (scaleFactor >= 1.5 && scaleFactor < 2) {
            blurFactor = 1; 
        } else if (scaleFactor >= 2 && scaleFactor < 2.5) {
            blurFactor = 2;
        } else if (scaleFactor >= 2.5) {
            blurFactor = 3;
        }


        flake.setAttribute('x', Math.round(random(0, svg.w/scaleFactor + scaleFactor*50)) );
        flake.setAttribute('y', -22);
        flake.style.strokeWidth = `${random(0.5, 2)}px`;

        if (blurFactor)
            flake.setAttribute('filter', `url(#blur${blurFactor})`);
 
    
        return {
            el : flake,
            factor : scaleFactor
        };
    };


    const animeFlake = () => {
        let flake = newFlake();
        let f = 0;
        const NF = 500;

        const animeDatas = {
            translateY : { start: 0, end: 540 },
            rotate : { start: 0, end: 100 }
        };

        const frame = () => {
            f += 1;
            const progress = f/NF;
            const ease = tfn.easeOutCubic(progress);

            flake.el.setAttribute(
                'transform',
                `translate(
                    0
                    ${transform(ease, animeDatas.translateY)}
                    )
                rotate(
                    ${transform(ease, animeDatas.rotate)}
                    )
                scale(
                    ${flake.factor}
                    )`
            );

            if ( !(f%NF) ) {    
                svg.removeChild(flake.el);
                return;
            }

            requestAnimationFrame(frame); 
        };

        svg.appendChild(flake.el);
        requestAnimationFrame(frame);
    };



    const play = () => {
        if (rafID) return;
        randomInterval(animeFlake, 20, 35);
    };

    const stop = () => {
        cancelAnimationFrame(rafID);
        rafID = null;
    };

    return {
        play: play,
        stop: stop
    };
}());

startBtn.addEventListener('click', () => {
    animePupil.play();
    animeEyelids.play();
    animeSnow.play();

}, false);

stopBtn.addEventListener('click', () => {
    animePupil.stop();
    animeEyelids.stop();
    animeSnow.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