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

              
                <svg version="1.1" id="sword" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="19.1px" height="84.3px" viewBox="0 0 19.1 84.3" enable-background="new 0 0 19.1 84.3" xml:space="preserve">
<ellipse fill="#9C4A23" stroke="#4F2222" stroke-miterlimit="10" cx="0" cy="0" rx="3.4" ry="11.3"/>
<line fill="none" stroke="#4F2222" stroke-linecap="round" stroke-miterlimit="10" x1="-3" y1="5.7" x2="3" y2="5.7"/>
<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="-9.0392" y1="-11.3346" x2="9.0441" y2="-11.3346">
	<stop  offset="0.15" style="stop-color:#FFFFFF"/>
	<stop  offset="0.15" style="stop-color:#F19344"/>
</linearGradient>
<rect x="-9" y="-13.2" fill="url(#SVGID_1_)" stroke="#4F2222" stroke-miterlimit="10" width="18.1" height="3.8"/>
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="-3.7395" y1="11.332" x2="3.7444" y2="11.332">
	<stop  offset="0.33" style="stop-color:#FFFFFF"/>
	<stop  offset="0.33" style="stop-color:#F19344"/>
</linearGradient>
<rect x="-3.7" y="9.5" fill="url(#SVGID_2_)" stroke="#4F2222" stroke-miterlimit="10" width="7.5" height="3.8"/>
<line fill="none" stroke="#4F2222" stroke-miterlimit="10" x1="0" y1="-13.2" x2="0" y2="-9.5"/>
<line fill="none" stroke="#4F2222" stroke-linecap="round" stroke-miterlimit="10" x1="-3" y1="-5.7" x2="3" y2="-5.7"/>
<line fill="none" stroke="#4F2222" stroke-linecap="round" stroke-miterlimit="10" x1="-3.4" y1="-1.9" x2="3.4" y2="-1.9"/>
<line fill="none" stroke="#4F2222" stroke-linecap="round" stroke-miterlimit="10" x1="-3.4" y1="1.9" x2="3.4" y2="1.9"/>
<linearGradient id="Blade_1_" gradientUnits="userSpaceOnUse" x1="-4.4142" y1="-41.543" x2="4.4191" y2="-41.543">
	<stop  offset="0.2" style="stop-color:#FFFFFF"/>
	<stop  offset="0.2" style="stop-color:#CCCCCC"/>
	<stop  offset="0.5" style="stop-color:#CCCCCC"/>
	<stop  offset="0.5" style="stop-color:#888888"/>
</linearGradient>
<polygon id="Blade" fill="url(#Blade_1_)" stroke="#4F2222" stroke-miterlimit="10" points="4.4,-65.2 0,-69.9 0,-69.9 -0.4,-69.4 
	-1,-68.8 -1.6,-68.2 -2.1,-67.6 -2.8,-66.9 -3.3,-66.4 -3.8,-65.8 -4.4,-65.2 -4.4,-64.4 -4.4,-63.6 -4.4,-62.9 -4.4,-62.1 
	-4.4,-61.3 -4.4,-60.2 -4.4,-13.2 4.4,-13.2 "/>
<line fill="none" stroke="#4F2222" stroke-linecap="round" stroke-miterlimit="10" x1="0" y1="-17.9" x2="0" y2="-62.7"/>
</svg>

              
            
!

CSS

              
                
              
            
!

JS

              
                var two = new Two({
  type: Two.Types.canvas,
  fullscreen: true,
  autostart: true
}).appendTo(document.body);

var physics = new Physics(2);

var mouse = new Two.Vector();
var vector = new Two.Vector();
var lines = [];

window.addEventListener('mousemove', function(e) {

  mouse.set(e.clientX, e.clientY);

}, false);

var sword;

var svg = two.interpret(document.querySelector('#sword'));

  sword = two.makeGroup();
  sword.scale = 3;
  sword.rect = svg.getBoundingClientRect();

  var drag = 0.33;
  var mass = 0.5;
  var strength = 1;
  var length = sword.rect.height;

  var spring = physics.makeSpring(
    physics.makeParticle(mass, mouse.x, mouse.y),
    physics.makeParticle(mass, mouse.x, mouse.y - length),
    strength, 0.7, length
  );
  spring.path = new Two.Path([new Two.Anchor(), new Two.Anchor()]);
  spring.a.position = spring.path.vertices[0];
  spring.b.position = spring.path.vertices[1];

  spring.a.makeFixed();
  var dragging = false;

  window.addEventListener('mousedown', function(e) {

    mouse.set(e.clientX, e.clientY);
    physics.gravity.set(0, 0);
    spring.a.velocity.clear();
    spring.a.force.clear();
    spring.b.velocity.clear();
    spring.b.force.clear();
    spring.constant = 1;
    spring.damping = 1;
    dragging = true;

  }, false);

  window.addEventListener('mousemove', function(e) {

    mouse.set(e.clientX, e.clientY);

    if (dragging) {

      spring.a.velocity.clear();
      spring.a.force.clear();

      spring.b.velocity.clear();
      spring.b.force.clear();

    }

  }, false);

  window.addEventListener('mouseup', function(e) {

    physics.gravity.set(0, 1);
    dragging = false;
    spring.constant = strength;
    spring.damping = 0.7;

  });

  for (var i = 0; i < 5; i++) {

    var pct = i / 4;
    var ir = (pct * length * 0.25 + length * 0.75) * 0.8;
    var or = ir;
    var line = new Two.ArcSegment(0, 0, ir, or, - Math.PI / 2, - Math.PI / 2, 32);

    line.linewidth = 2;
    line.stroke = '#ccc';
    line.cap = 'round';
    line.opacity = 0.66;

    sword.add(line);
    lines.push(line);

  }

  sword.add(svg);

  two.bind('update', function(frameCount) {

    physics.update();

    sword.translation.addSelf(
      vector.copy(mouse)
        .subSelf(sword.translation)
        .multiplyScalar(drag)
    );

    spring.a.position.copy(sword.translation);

    var angle = Two.Utils.angleBetween(
      spring.a.position, spring.b.position);

    var rotation = sword.rotation;
    sword.rotation = angle - Math.PI / 2;
    var rd = (sword.rotation - rotation);
    var visible = Math.abs(rd) > 0.001;

    if (rd > Math.PI) {
      rd -= Math.PI * 2;
    } else if (rd < - Math.PI) {
      rd += Math.PI * 2;
    }

    for (var i = 0; i < lines.length; i++) {

      if (!visible) {
        lines[i].visible = false;
        continue;
      }

      lines[i].startAngle = - Math.PI / 2;
      lines[i].endAngle = (lines[i].startAngle
        - rd * Math.sqrt((i + 1) / lines.length));

      lines[i].visible = true;
    }

  });
              
            
!
999px

Console