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

+ add another resource


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


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.


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.


                <script src=""></script>
  <p> <input type='text' id='theText' value='BBB' /> <button id='st'>Change text</button> </p> 
<div  id='container1' style="width: 300px, height: 200px;"></div>



  margin: 0 5px;
  margin: 0 5px 5px 0;


                // Set up the canvas / stage
var s1 = new Konva.Stage({container: 'container1', width: 300, height: 200});

// Add a layer for line
var layer = new Konva.Layer({draggable: false});

// just a plain JS object to keep common variables in hand.
var cfg = { w: 300, h: 200, r: 80, txtSize: 520};

var group = new Konva.Group();
var circle = new Konva.Circle({x: cfg.w/2, y: cfg.h/2, radius: cfg.r, fill: 'DodgerBlue', stroke: 'DeepPink', strokeWidth: 5})

// make the text 
var textValue = new Konva.Text({
  id: "t1",
  x: cfg.w/2,
  y: cfg.h/2,
  text: '',
  fill: 'DeepPink ',
  fontSize: cfg.txtSize
textValue.offset({x: textValue.getWidth()/2, y: textValue.getHeight()/2});


// to spin a group about a point, set the offset to that point, then set the x & y to that point to !
var pos = group.getClientRect();
RotatePoint(group, {x: pos.x + pos.width/2, y: pos.y + pos.height/2});

// Everything is ready so draw the canvas objects set up so far.

$('#st').on('click', function(){
  var txt = $('#theText').val();

// set the offset for rotation to the given location and re-position the shape
function RotatePoint(shape, pos){  // where pos = {x: xpos, y: yPos}
var initialPos = shape.getAbsolutePosition();
var moveBy = {x: pos.x - initialPos.x, y: pos.y - initialPos.y};

// offset is relative to initial x,y of shape, so deduct x,y.

shape.x(initialPos.x + moveBy.x);
shape.y(initialPos.y + moveBy.y);

var setValue = function(newText){

		// work out scaling to make text fit into the circle

		var txt = this.layer.find('#t1')[0];
		txt.text(newText).scale({x:1, y: 1})
		var txtSize = txt.getClientRect();

    var maxW = (cfg.r); // max allowed width of text
		var txtScaleW = (txtSize.width > maxW ? ( maxW / txtSize.width) : 1);

		var maxH = cfg.r; // max allowed height of text
		var txtScaleH = (txtSize.height > maxH ? ( maxH / txtSize.height) : 1);

		// finally decide which is the worst case and use that scaling
		var txtScale = ( txtScaleW > txtScaleH ? txtScaleH : txtScaleW);

    txt.scale({x: txtScale, y: txtScale});

    txt.offset({x: txt.getWidth()/2, y: txt.getHeight()/2});
  // set initial text & spin !
// The magin animation config.
  var anim, pos = 0, frameCnt = 0
  if (anim) {anim.stop(); }
  anim = new Konva.Animation(function(frame) {
    frameCnt = frameCnt + 1;
    if (frameCnt % 2 === 0){
      pos = pos + .2
      var scaleX = Math.sin(pos);
      textValue.visible(scaleX < 0 ? false : true);
  }, layer);