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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <canvas id='canvas' height='300px' width='300px'></canvas>
<div class='controls'>
  <h3>Controls</h3>
  <label for="burst">No. of Burst:</label>
  <input id="burst" class="slider" type="range" value="18" min="12" max="36" step='2' title="Adjust slider to increase or decrease burst" />
  <br/>
  <label for="content">Text Content:</label>
  <input type="text" id="content" maxlength="5" />
  <br/>
  <label for="dropshadow">Shadow?</label>
  <input type="checkbox" id="dropshadow" />
  <br/>
  <label for="animation">Animation?</label>
  <input type="checkbox" id="animation" />
</div>


<!--Fiddle: http://jsfiddle.net/bbojcrgg/2/ -->
              
            
!

CSS

              
                /* For demo only */

.controls {
  float: right;
  padding: 5px;
  margin: 50px;
  line-height: 25px;
  border: 1px solid;
  box-shadow: 1px 1px 0px #222;
}

label,
input {
  display: inline-block;
  vertical-align: middle;
  text-align: left;
}

h3 {
  padding: 10px;
  text-align: center;
}

label {
  width: 100px;
}

input[type='range'], input[type='text'] {
  width: 100px;
}

body {
  font-family: Calibri;
  background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);
}
              
            
!

JS

              
                window.onload = function() {
  var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  var defaultBurst = 18,
    defaultContent = "New",
    offset = 0, anim;

  function paint(numBurst, text, needShadow, needAnim) {
    var totalLength = 0;
    if (!numBurst) numBurst = defaultBurst;
    if (!text) text = defaultContent;
    ctx.clearRect(0, 0, canvas.width, canvas.height); //clear before every repaint
    var angleInRad = Math.PI * (360 / numBurst) / 180;
    var deltaAngleInRad = angleInRad / 2;
    ctx.moveTo(75, 150);
    ctx.beginPath();
    for (i = 0; i <= numBurst; i++) {
      x1 = 75 * Math.cos(angleInRad * i) + 150;
      y1 = 75 * Math.sin(angleInRad * i) + 150;
      x2 = 60 * Math.cos((angleInRad * i) + deltaAngleInRad) + 150;
      y2 = 60 * Math.sin((angleInRad * i) + deltaAngleInRad) + 150;
      ctx.lineTo(x1, y1);
      ctx.lineTo(x2, y2);
      totalLength += calcLength(x1, y1, x2, y2); //calculate length of path
    }
    /* total Length * 2 is used because we calculate only distance between x1,y1 to x2,y2 but not x2,y2 to next x1,y1 (both will be same as point is in center) */
    ctx.setLineDash([totalLength * 2, totalLength * 2]);
    ctx.fillStyle = 'crimson';
    if (needAnim) {
      if (offset <= 0) offset = totalLength * 2;
      offset -= 1;
      ctx.lineDashOffset = offset;
      ctx.strokeStyle = 'crimson';
      if (offset >= 0) {
        anim = window.requestAnimationFrame(function() {
          paint(numBurst, text, needShadow, needAnim);
        }); //animate till stroke is complete
      } else {
        window.cancelAnimationFrame(anim);
        dropShadow(needShadow);
        ctx.fill();
        addText(text);
      }
      dropShadow(false); //avoid shadow when animation is on
      ctx.stroke();
    } else {
      dropShadow(needShadow);
      ctx.fill();
      addText(text);
    }
  }

  /* Adds a Shadow if flag is set */
  function dropShadow(flag) {
    if (flag) {
      ctx.shadowOffsetX = 5;
      ctx.shadowOffsetY = 5;
      ctx.shadowBlur = 5;
      ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
    } else {
      ctx.shadowOffsetX = 0;
      ctx.shadowOffsetY = 0;
      ctx.shadowBlur = 0;
      ctx.shadowColor = "none";
    }
  }

  /* Adds text inside the shape */
  function addText(text) {
    ctx.font = "32px Arial";
    ctx.textAlign = "center"; // horizontal middle
    ctx.textBaseline = "middle"; //vertical middle
    ctx.fillStyle = "gold";
    ctx.fillText(text, 150, 150, 120);
  }

  /* Calculate the distance between two points */
  function calcLength(x1, y1, x2, y2) {
    x = x2 - x1;
    y = y2 - y1;
    return Math.sqrt(x * x + y * y);
  }

  paint(); //default paint

  /* Control Event Listeners */

  var slider = document.getElementById('burst');
  var textInput = document.getElementById('content');
  var shadow = document.getElementById('dropshadow');
  var animation = document.getElementById('animation');

  slider.addEventListener('change', function() {
    offset = 0;
    if(animation.checked)
      window.cancelAnimationFrame(anim);
    paint(this.value, textInput.value, shadow.checked, animation.checked);
  });

  textInput.addEventListener('blur', function() {
    offset = 0;
    if(animation.checked)
      window.cancelAnimationFrame(anim);
    paint(slider.value, this.value, shadow.checked, animation.checked);
  });

  shadow.addEventListener('change', function() {
    offset = 0;
    if(animation.checked)
      window.cancelAnimationFrame(anim);
    paint(slider.value, textInput.value, this.checked, animation.checked);
  });
  animation.addEventListener('change', function() {
    if(!this.checked){
      window.cancelAnimationFrame(anim);
      offset = 0;
    }
    paint(slider.value, textInput.value, shadow.checked, this.checked);
  });

};
              
            
!
999px

Console