123

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Rainbow Button owo</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <h1 class="rainbow-name">
            <canvas class="rainbow-name__canvas" width="930" height="418"></canvas>
            <img class="rainbow-name__image" src="https://acupoftee.github.io/images/name.png" alt="Dusty Button">
        </h1>
        <script src="main.js"></script>
    </body>
</html>
            
          
!
            
              body {
    background: #020916;
}
.rainbow-name {
    position: relative;
    margin: 100px 10%;
    max-width: 1000px;
  }
  
  .rainbow-name__canvas {
    position: absolute;
    left: 0px;
    top: 0;
    width: 110%; 
  }
  
  .rainbow-name__image {
    display: block;
    width: 100%;
    position: relative;
  }
  
            
          
!
            
              var wordmark = document.querySelector('.rainbow-name');

var wordmarkImg = wordmark.querySelector('.rainbow-name__image');
var canvas = wordmark.querySelector('.rainbow-name__canvas');
var ctx = canvas.getContext('2d');
var trailCount = 100;
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;

var nameImage = new Image();
nameImage.onload = onImageLoad;
nameImage.src = "https://acupoftee.github.io/images/name.png";

function onImageLoad() {
  setColorCanvas( 'blue', '#5ab3b5' );
  setColorCanvas( 'gold', '#EA0' );
  setColorCanvas( 'orange', '#E62' );
  setColorCanvas( 'magenta', '#C25' );
  animate();
}

var colorCanvases = {};

function setColorCanvas( name, color ) {
  var colorCanvas = document.createElement('canvas');
  colorCanvas.width = nameImage.width;
  colorCanvas.height = nameImage.height;
  var colorCtx = colorCanvas.getContext('2d');
  colorCtx.drawImage( nameImage, 0, 0 );
  colorCtx.globalCompositeOperation = 'source-in';
  colorCtx.fillStyle = color;
  colorCtx.fillRect( 0, 0, nameImage.width, nameImage.height );
  colorCanvases[ name ] = colorCanvas;
}


var t = 0;
var rainbow = [];

(function() {
  for ( var i=0; i < trailCount; i++ ) {
    rainbow.push(null);
  }
})();

var colorCycle = [ 'blue', 'gold', 'orange', 'magenta' ];

function animate() {
  update();
  render();
  requestAnimationFrame( animate );
}

function update() {
  t++;
  var colorCycleIndex = Math.floor( t / 8 ) % 4;
  var nextColor =  colorCycle[ colorCycleIndex ];
  rainbow.pop();
  rainbow.pop();
  rainbow.pop();
  rainbow.unshift( nextColor );
  rainbow.unshift( nextColor );
  rainbow.unshift( nextColor );
}

function render() {
  ctx.clearRect( 0, 0, canvasWidth, canvasHeight );

  // iterate backwards through rainbow
  for ( var i = rainbow.length-1; i >= 0; i-- ) {
    var color = rainbow[i];
    if ( color ) {
      ctx.drawImage( colorCanvases[ color ], i+1, i+1 );
    }
  }
}
            
          
!
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.

Console