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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <section class="support" style="display:none">
  <h2 class="suport-header">Experimental Web Platform Feature</h2>
  <div class="support-content">
    <span>This demo requires Experimental Web Platform features to be enabled in Chrome or Opera. You can copy and paste this in your address bar to enable it.</span>
    <div class="flags">about://flags/#enable-experimental-web-platform-features</div>
  </div>  
</section>

<main class="main" style="display:none">
  <header class="controls">
    <button id="start-button">Start Paint</button>
  </header>
  <section class="main-content">
    <div id="logo1" class="logo"></div>
    <div id="logo2" class="logo"></div>
  </section>  
</main>

<script id="worklet-code" type="text/worklet">
    
  // Mostly based on https://github.com/bfgeek/houdini-examples/tree/gh-pages/google_logo
  
  const HALF_STROKE_WIDTH = 0.55 / 2;
  const LISTENING_WOBBLE = 0.4;
  const LISTENING_SMOOTHING_MULTIPLIER = [0.6, 1, 1, 0.6];

  const interpolate = function(start, end, time) {
    return (1 - time) * start + time * end;
  };

  const Interpolator = function(relativeLengthOfMainChange, startDelay) {
    this.relativeLengthOfMainChange = relativeLengthOfMainChange;
    this.startDelay = Math.min(1-relativeLengthOfMainChange, startDelay);
  };

  Interpolator.prototype.interpolate = function(input) {
    let val = (input - this.startDelay) / this.relativeLengthOfMainChange;
    val = Math.max(0, Math.min(1, val));
    return (input + val) / 2;
  };

  var Stroker = function(x, y, dotX, dotY, draw, interpolator, red) {
    this.x = x;
    this.y = y;
    this.dotX = dotX;
    this.dotY = dotY;
    this.draw = draw;
    this.interpolator = interpolator;
    this.red = !!red;
  };

  var drawUppercaseG = function(ctx, time) {
    ctx.save();
    ctx.strokeStyle = 'rgb(66,133,244)';
    const x = interpolate(this.dotX, this.x, time);
    const y = interpolate(this.dotY, this.y, time);
    const radius = interpolate(0, 1.8, time);
    if (radius < 0.5) {
      ctx.beginPath();
      ctx.arc(x, y, 0.275, 0, 2*Math.PI);
      ctx.stroke();
    } else {
      ctx.beginPath();
      ctx.moveTo(x + 0.1, y);
      ctx.lineTo(x + radius, y);
      ctx.arc(x, y, radius, 0, 315/180*Math.PI);
      ctx.stroke();
    }
    ctx.restore();
  };

  var drawLowercaseO = function(ctx, time) {
    ctx.save();
    ctx.strokeStyle = this.red ? 'rgb(234,67,53)' : 'rgb(251,188,5)';
    const x = interpolate(this.dotX, this.x, time);
    const y = interpolate(this.dotY, this.y, time);
    const radius = Math.max(0.275, interpolate(0, 1.1, time));
    ctx.beginPath();
    ctx.arc(x, y, radius, 0, 2*Math.PI);
    ctx.stroke();
    ctx.restore();
  };

  var drawLowercaseG = function(ctx, time) {
    ctx.save();
    ctx.strokeStyle = 'rgb(66,133,244)';
    const x = interpolate(this.dotX, this.x, time);
    const y = interpolate(this.dotY, this.y, time);
    const radius = interpolate(0, 1.05, time);
    if (radius < 0.275) {
      ctx.save();
      ctx.lineWidth = radius * 2;
      ctx.beginPath();
      ctx.arc(x, y, radius, 0, 2*Math.PI);
      ctx.stroke();
      ctx.restore();
    } else {
      ctx.beginPath();
      ctx.moveTo(x + radius, y - radius - HALF_STROKE_WIDTH);
      ctx.lineTo(x + radius, y + radius + HALF_STROKE_WIDTH);
      ctx.ellipse(x, y + HALF_STROKE_WIDTH + radius, radius, radius, 0, 0, 160/180*Math.PI);
      ctx.stroke();

      ctx.beginPath();
      ctx.arc(x, y, radius, 0, 2*Math.PI);
      ctx.stroke();
    }
    ctx.restore();
  };

  var drawLowercaseL = function(ctx, time) {
    ctx.save();
    ctx.strokeStyle = 'rgb(52,168,83)';
    const x = interpolate(this.dotX, this.x, time);
    const y1 = interpolate(this.dotY, 1.33, time);
    const y2 = interpolate(this.dotY, -2.75, time);
    const radius = (y1 - y2) / 4;
    if (radius < 0.275) {
      ctx.beginPath();
      ctx.arc(x, (y1 + y2) / 2, 0.275, 0, 2*Math.PI);
      ctx.stroke();
    } else {
      ctx.beginPath();
      ctx.moveTo(x,y1);
      ctx.lineTo(x,y2);
      ctx.stroke();
    }
    ctx.restore();
  };

  var drawLowercaseE = function(ctx, time) {
    ctx.save();
    ctx.strokeStyle = 'rgb(234,67,53)';
    const x = interpolate(this.dotX, this.x, time);
    const y = interpolate(this.dotY, this.y, time);
    const radius = interpolate(0, 1.05, time);
    if (radius < 0.275) {
      ctx.save();
      ctx.lineWidth = radius * 2;
      ctx.beginPath();
      ctx.arc(x, y, radius, 0, 2*Math.PI);
      ctx.stroke();
      ctx.restore();
    } else {
      const lineRadius = radius + HALF_STROKE_WIDTH;
      const startAngle = 160/180*Math.PI;
      const startX = x + Math.cos(startAngle) * radius;
      const startY = y + Math.sin(startAngle) * radius;
      const endAngle = 335/180*Math.PI;
      const endX = x + Math.cos(endAngle) * lineRadius;
      const endY = y + Math.sin(endAngle) * lineRadius;
      ctx.beginPath();
      ctx.arc(x, y, radius, 30/180*Math.PI, 335/180*Math.PI);
      ctx.moveTo(endX, endY);
      ctx.lineTo(startX, startY);
      ctx.stroke();
    }
    ctx.restore();
  };

  const GOOGLE_LOGO = [
    new Stroker(-6.65, -0.7, -3, 0, drawUppercaseG, new Interpolator(.5, 0)),
    new Stroker(-2.95, 0, -1, 0, drawLowercaseO, new Interpolator(.5, .1), true),
    new Stroker(0.1, 0, 1, 0, drawLowercaseO, new Interpolator(.5, .2)),
    new Stroker(5.1, 0, 3, 0, drawLowercaseL, new Interpolator(.5, .3)),
    new Stroker(3.05, 0, 2, 0, drawLowercaseG, new Interpolator(.5, .4)),
    new Stroker(7.1, 0, 4, 0, drawLowercaseE, new Interpolator(.5, .5))
  ];

  registerPaint("logo", class {
    
	  static get inputProperties() { 
      return [
        "--scale",
        "--total-time"
      ]; 
    }
  
    constructor() {      
      console.log("Logo paint process started");
    }

    paint(ctx, geom, styleMap, args) {
            
      let actualTime = parseFloat(styleMap.get('--scale').toString()) || 0;
      let totalTime = parseFloat(styleMap.get('--total-time').toString()) || 0;      
      
      if (actualTime < 0) {
        actualTime = 0;
      } 
      
      ctx.translate(geom.width / 2, geom.height / 2);
      const factor = Math.min(geom.width, geom.height) / 2 / 9;
      ctx.scale(factor, factor);

      for (let i = 0; i < 4; i++) {
        let yDiff = Math.sin(Math.PI / 700 * totalTime + i * Math.PI / 2) * LISTENING_WOBBLE + LISTENING_WOBBLE;
        yDiff *= LISTENING_SMOOTHING_MULTIPLIER[i];
        GOOGLE_LOGO[i].dotY = yDiff;
      }

      ctx.lineWidth = 0.55; 

      for (let i = 0; i < GOOGLE_LOGO.length; i++) {
        const stroker = GOOGLE_LOGO[i];
        const time = stroker.interpolator.interpolate(actualTime);
        stroker.draw(ctx, time);
      }
    }
  });
  
</script>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  font-family: Roboto, 'Segoe UI', Tahoma, sans-serif;
}

button {
  padding: 8px 10px;
  cursor: pointer;
}

.support {
  padding: 0 10px;
  margin: 40px auto;
  max-width: 700px;
  width: 100%;
}

.support-header {
  font-weight: 400;
  color: rgba(0, 0, 0, 0.86);
  margin: 10px 0;
}

.support-content {
  color: rgba(0, 0, 0, 0.54);
  line-height: 1.45;
}

.flags {
  font-weight: 700;
  margin: 6px 0;
}

.controls {
  padding: 10px;
}

.main-content {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.logo {  
  width: 100%;
  height: 400px;
}

#logo2 {
  width: 50%;
  max-width: 300px;
}

@supports (background-image: paint(logo)) {
  
  .logo.is-loaded {
    background-image: paint(logo);
  }
}

              
            
!

JS

              
                console.clear();

if (typeof CSS.paintWorklet === "undefined") {
    
  document.querySelector(".support").style.display = "block";
  
} else {
    
  document.querySelector("main").style.display = "block";
  
  const startButton = document.querySelector("#start-button");
  startButton.addEventListener("click", onClick);
  
  function onClick() {    
    startButton.disabled = true;
    startButton.removeEventListener("click", onClick);
    TweenLite.to(startButton, 2, { autoAlpha: 0 });
    registerCSS().then(main);  
  }
}

function registerCSS() {
  
  CSS.registerProperty({
    name: "--scale",
    syntax: "<number>",
    inherits: false,
    initialValue: "0",
  });

  CSS.registerProperty({
    name: "--total-time",
    syntax: "<number>",
    inherits: false,
    initialValue: "0",
  });
  
  const workletCode = document.querySelector("#worklet-code").textContent;
  const blob = new Blob([workletCode], { type: "text/javascript" });
  return CSS.paintWorklet.addModule(URL.createObjectURL(blob));
}

function main() {
      
  const logo1 = document.querySelector("#logo1");
  const logo2 = document.querySelector("#logo2");
  
  logo1.classList.add("is-loaded");
  logo2.classList.add("is-loaded");
  
  TweenMax.to(logo1, 0.5, {
    "--scale": 1,
    repeat: -1,
    repeatDelay: 2,
    yoyo: true,
    ease: Power2.easeOut,
    delay: 2
  });
  
  TweenMax.from(logo2, 0.5, {
    "--scale": 1,
    repeat: -1,
    repeatDelay: 2,
    yoyo: true,
    ease: Power2.easeOut,
    delay: 1
  });
    
  updateTotalTime();
  
  function updateTotalTime(totalTime = performance.now()) {    
    logo1.style.setProperty("--total-time", totalTime);
    logo2.style.setProperty("--total-time", totalTime);
    requestAnimationFrame(updateTotalTime);
  }
}

              
            
!
999px

Console