Pen Settings

HTML

CSS

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

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

              
                - var totalSize = 400
- var o = totalSize / 2 // origin
- var ballSize = totalSize / 2
- var yellow = 'hsla(31,62%,65%, 1)';// 'hsla(44,100%,58%, 1)'
- var yellowDark = 'hsla(31,62%,55%, 1)'
- var yellowDarker = 'hsla(31,62%,30%, 1)'
- var yellowDarkest = 'hsla(31,62%,10%, 1)'

form
  - var fields = ['y', 'w', 'wTop', 'wBottom', 'h1', 'h1a', 'h2', 'h2a', 'h3']
  each field in fields
    div
      label #{field}
      input(type="range" min="0" max=totalSize name=field)

svg(viewBox=`0 0 ${totalSize} ${totalSize}`, xmlns='http://www.w3.org/2000/svg', width=totalSize, height=totalSize)
  defs
  
    lineargradient#grad1(x1='0%', y1='0%', x2='100%', y2='0%')
      stop(offset='0%', style='stop-color:rgb(255,255,0); stop-opacity:1')
      stop(offset='100%', style='stop-color:rgb(255,0,0); stop-opacity:1')
      
    radialgradient(id="mouth-gradient" cx="50%" cy="50%" r="100%" fx="50%" fy="0%")
      stop(offset='0%', style=`stop-color: ${yellowDarkest}; stop-opacity:1`)
      stop(offset='100%', style=`stop-color: ${yellowDarker}; stop-opacity:1`)
      
    radialGradient(id="head-gradient" cx="50%" cy="50%" r="100%" )
      stop(offset="0%" style=`stop-color: ${yellow}; stop-opacity: 1`)
      stop(offset="50%" style=`stop-color: ${yellowDark}; stop-opacity: 1`)
      
    radialGradient(id="inner-eye-gradient" cx="0%" cy="00%" r="75%" fx="10%" fy="10%")
      stop(offset="0%" style=`stop-color: #444; stop-opacity: 1`)
      stop(offset="100%" style=`stop-color: black; stop-opacity: 1`)
      
    radialGradient(id="outer-eye-gradient" cx="50%" cy="25%" r="75%" fx="50%" fy="50%")
      stop(offset="0%" style=`stop-color: white; stop-opacity: 1`)
      stop(offset="100%" style=`stop-color: #ddd; stop-opacity: 1`)      
      
    filter(id="gaussian" x="0" y="0")
      feGaussianBlur(in="SourceGraphic" stdDeviation="10")
      
    filter(id="shadow" x="0" y="0")
      feDropShadow( dx="0" dy="4" stdDeviation="0")
      feComponentTransfer 
        feFuncA(type="linear" slope=".1")
      feMerge
        feMergeNode
        feMergeNode(in="SourceGraphic")
        
    filter(id="shadow-bocca" x="0" y="0")
      feDropShadow( dx="0" dy="-4" stdDeviation="0")
      feComponentTransfer 
        feFuncA(type="linear" slope=".1")
      feMerge
        feMergeNode
        feMergeNode(in="SourceGraphic")
        
    
      
  // /defs
  
  
      
  // Face
  circle.face(cx=totalSize - (ballSize), cy=totalSize - ballSize, r=ballSize fill="url(#head-gradient)")
    
  // Eyes
  g()
    - var x = o + (ballSize / 4)
    - var y = o - (ballSize / 9)
    - var outerSize = ballSize / 3.4
    - var innerSize = ballSize / 12        
    circle.eye(cx=o - (ballSize / 3) cy=y r=outerSize fill="url(#outer-eye-gradient)" filter="url(#shadow)")
    circle.eye(cx=o + (ballSize / 3) cy=y r=outerSize fill="url(#outer-eye-gradient)" filter="url(#shadow)")
    circle.eye(cx=o - (ballSize / 4) cy=y r=innerSize fill="url(#inner-eye-gradient)" )
    circle.eye(cx=o + (ballSize / 4) cy=y r=innerSize fill="url(#inner-eye-gradient)" )
    
  // Eyebrows
  g(fill="none" stroke=yellowDarkest stroke-width="20" filter="url=(#shadow-bocca)")
    - var y = 100
    path.eyebrow(d=`M ${o-30} ${y-10} Q ${o-60} ${y-10} ${o-90} ${y}` )
    path.eyebrow(d=`M ${o+30} ${y-10} Q ${o+60} ${y-10} ${o+90} ${y}`)
    
  // Mouth
  clipPath#mouth-clip
    - var x = o
    - var y = o + (ballSize / 2)
    - var w = ballSize / 1.5
    - var h = ballSize / 6
    path#mouth()
    
  
  
  // Mouth BG
  circle#mouth-bg(cx=totalSize - (ballSize) cy=totalSize - ballSize r=ballSize clip-path="url(#mouth-clip)" fill="url(#mouth-gradient)" filter="url(#shadow-bocca)" )
  
  // Teeth
  ellipse#teeth(cx=o cy=o+30 rx="120" ry="50" r=outerSize fill="#ccc" clip-path="url(#mouth-clip)" filter="url(#shadow-bocca)" )
  
  // Tongue
  ellipse#tongue(cx=o cy=o+180 rx="80" ry="50" r=outerSize fill="#ed000033" clip-path="url(#mouth-clip)")
  

              
            
!

CSS

              
                $yellow = #ffc72c;

body
  background hsla(31,62%,55%, 1)//#ccc
  display flex
  justify-content center
  align-items center
  height 100vh
  position relative
  font-family "Sacramento"
  
form
  position fixed
  top 0
  left 0
  width 300px
  padding 30px
  display none
  // border 1px solid 
              
            
!

JS

              
                console.clear();

const totalSize = 400,
  o = totalSize / 2, // origin
  ballSize = totalSize / 2
;

const mouth = document.getElementById('mouth');

const moods = {
  ooh: {
    y: 280,  
    w: 20,
    wTop: 10,
    wBottom: 12,
    h1: 0,
    h1a: 15,
    h2: 30,
    h2a: 45,    
    h3: 60
  },
  smile: {
    h1: 102,
    h1a: 43,
    h2: 21,
    h2a: 37,
    h3: 99,
    w: 133,
    wBottom: 88,
    wTop: 88,
    y: 228
  },
  bigSmile: {
    y: 220,  
    w: 150,
    wTop: 70,
    wBottom: 90,
    h1: 40,
    h1a: 0,
    h2: 50,
    h2a: 100,
    h3: 140
  },
  gh: {
    y: 270,  
    w: 100,
    wTop: 20,
    wBottom: 50,
    h1: 30,
    h1a: 10,
    h2: 45,
    h2a: 80,
    h3: 50
  },
  ggg: {
    y: 240,  
    w: 130,
    wTop: 50,
    wBottom: 50,
    h1: 30,
    h1a: 10,
    h2: 45,
    h2a: 80,
    h3: 60
  },
  sad: {
    y: 250,  
    w: 130,
    wTop: 30,
    wBottom: 70,
    h1: 40,
    h1a: 50,
    h2: 80,
    h2a: 120,
    h3: 60
  },
  what: {
    h1: 38,
    h1a: 36,
    h2: 42,
    h2a: 52,
    h3: 44,
    w: 85,
    wBottom: 70,
    wTop: 30,
    y: 245
  },
  custom: {
    y: 250,  
    w: 130,
    wTop: 30,
    wBottom: 70,
    h1: 40,
    h1a: 50,
    h2: 80,
    h2a: 120,
    h3: 60
  },
}; 


function makeMouth (c) {
  const p = {
    a: `${o} ${c.y+c.h1}`,
    a1: `${o-c.wTop} ${c.y+c.h1}`,
    a2: `${o+c.wTop} ${c.y+c.h1}`,
    b: `${o+c.w} ${c.y+c.h2}`,   
    b1: `${o+c.w} ${c.y+c.h1a}`,   
    b2: `${o+c.w} ${c.y+c.h2a}`,   
    c: `${o} ${c.y+c.h3}`,
    c1: `${o+c.wBottom} ${c.y+c.h3}`,
    c2: `${o-c.wBottom} ${c.y+c.h3}`,
    d: `${o-c.w} ${c.y+c.h2}`,
    d1: `${o-c.w} ${c.y+c.h2a}`,
    d2: `${o-c.w} ${c.y+c.h1a}`
  };
  return [
    `M ${p.a}`,
    `C ${p.a2} ${p.b1} ${p.b}`,
    `C ${p.b2} ${p.c1} ${p.c} `,
    `C ${p.c2} ${p.d1} ${p.d}`,
    `C ${p.d2} ${p.a1} ${p.a}`
  ].join('');
}

mouth.setAttribute('d', makeMouth(moods.what) )



const timeline = new TimelineMax({
  repeat: 20
});
timeline.add( TweenMax.to("#mouth", .7, { ease: Elastic.easeOut.config(1, 0.6), attr: { d: makeMouth(moods.bigSmile) } }) );
// timeline.add( TweenMax.to("#mouth", .6, { attr: { d: makeMouth(moods.smile) } }) );
timeline.add( TweenMax.to("#mouth", .6, { ease: Elastic.easeOut.config(1, 0.9), attr: { d: makeMouth(moods.ooh) } }) );
timeline.add( TweenMax.to("#mouth", .7, { ease: Elastic.easeOut.config(1, 0.6), attr: { d: makeMouth(moods.ggg) } }) );
timeline.add( TweenMax.to("#mouth", .7, { ease: Elastic.easeOut.config(1, 0.6), attr: { d: makeMouth(moods.gh) } }) );

timeline.add( TweenMax.to("#mouth", 1.7, { ease: Elastic.easeOut.config(1, 0.6), attr: { d: makeMouth(moods.what) } }) );
timeline.timeScale( .5 );
//timeline.stop();


mouth.addEventListener('click', function() {
  // timeline.stop();
});

document.querySelectorAll('input').forEach( item => {
  item.addEventListener('change', function (e) {
    timeline.stop();
    item.title = item.value;
    moods.custom[item.name] = parseInt(item.value);
    console.log(moods.custom)
    mouth.setAttribute('d', makeMouth(moods.custom) )
  });
})
              
            
!
999px

Console