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.



This Pen shows how a computer renders a cubic bezier curve, as used in design and motion graphics programs. This Pen is part of an an article titled Mastering the Bezier Curve in Sketch.

~ Made by Peter Nowell @pnowelldesign, with help from Antoine and Julien Quint @graouts @pom


<svg width="550px" height="350px" viewBox="0 0 550 350" version="1.1" style="display:block; margin:100px auto 0 auto;">
    <!-- Generator: Sketch 3.0.4 (8053) -->
    <title>Cubic Bezier example</title>
    <g id="Bezier-Curves" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
        <g id="Cubic-Bezier-example" transform="translate(-72.000000, -72.000000)">

          <!-- Animate a circle radius from 0 to 1 to have the t parameter -->
          <circle id="t" fill="none" stroke="none">
              <animate attributeType="XML" attributeName="r" from="0" to="1" dur="7s" repeatCount="indefinite"/>

          <!--Main Curve --> 
          <path d="M100,400 C100,153 300,99.9999999 600,192" id="main-curve" stroke="#000000" stroke-width="2" fill-opacity="0.179206295" fill="#D8D8D8" stroke-dasharray="657.7994384765625" stroke-dashoffset="657.7994384765625">
            <animate id="introMainCurve" attributeName="stroke-dashoffset" attributeType="XML" from="657.7994384765625" to="0" begin="0s" dur="7s" repeatCount="indefinite" calcMode="spline" keySplines="0.37 0.39 0.56 0.39" keyTimes="0;1" />
          <!--Left Handle--> 
          <path d="M99,153.474639 L99,276.741808 L99,338.375393 L99,400.008977" id="left-handle" stroke="#5C60EC" stroke-width="2" stroke-linecap="square"></path>
          <!--Right Handle-->
          <path d="M299.938027,99.7211217 L374.703522,122.790841 L449.469018,145.860561 L599.000008,192" id="right-handle" stroke="#5C60EC" stroke-width="2" stroke-linecap="square"></path>
          <!--Upper Dotted Line-->
          <path d="M100,153.5 L150.124892,140.247525 L200.249783,126.99505 L300.499566,100.4901" id="upper-dotted-line" stroke="#979797" stroke-linecap="square" stroke-dasharray="1,3">
            <animate id="introUpperDottedLine" attributeType="XML" attributeName="stroke-opacity" from="0" to="1" dur="1" begin="1s" />
            <!--begin="one.begin+3s" dur="10s"-->
          <!--Lower Dotted Line-->
          <path d="M100,400 L600.501002,192.192116" id="lower-dotted-line" stroke="#979797" stroke-linecap="square" stroke-dasharray="1,3"></path>
          <!--Cubic Drawing Triangle-->
          <polyline stroke="#95cf29" stroke-width="2" id="triangle">
              <animate attributeType="XML" attributeName="points" from="100,400 100,153 300,100" to="100,153 300,100 600,192" dur="7s" repeatCount="indefinite"/>
          <!--Cubic Drawing Triangle-->
          <path d="M100,400 L100,153 L300,100" id="cubic-drawing-triangle-50" stroke="#95CF29" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <animate id="special"
             attributeName="d" attributeType="XML"
             from="M100,400 L100,153 L300,100" to="M100,153 L300,100 L600,192"
             begin="0s" dur="7s" repeatCount="indefinite"></animate>
          <!-- Tangent line -->
          <line stroke="#DE40CD" stroke-width="2" stroke-linecap="round" id="tangentLine"/>
          <!--Tangent Point -->
          <circle r="4" fill="#DE40CD" id="tangentPoint"/>
          <!--Control Point Dots-->
          <circle id="controlPoint1" cx="99" cy="154" r="4" fill="white" stroke="#5C60EC" stroke-width="2"></circle>
          <circle id="controlPoint2" cx="301" cy="100" r="4" fill="white" stroke="#5C60EC" stroke-width="2"></circle>
          <circle id="controlPoint0" cx="99" cy="400" r="4" fill="#5C60EC" stroke="#5C60EC" stroke-width="2"></circle>
          <circle id="controlPoint0" cx="600" cy="192" r="4" fill="#5C60EC" stroke="#5C60EC" stroke-width="2"></circle>

<!-- Link to the Article -->
<a href="" style="display:block; margin-top:80px; font-family:Avenir,Helvetica Neue,sans-serif; color:#9DAAC4; text-align:center;">&lpar;Part of the Article&rpar; Mastering the Bezier Curve in Sketch</a>
              var circle = document.getElementById("t");
var poly = document.querySelector("polyline");
var tangentLine = document.getElementById("tangentLine");
var tangentPoint = document.getElementById("tangentPoint");

function animateTangent() {
  if (poly.animatedPoints.numberOfItems == 0) {
    var t = circle.r.animVal.value;
    var u = 1 - t;
    var p1 = poly.animatedPoints.getItem(0);
    var p2 = poly.animatedPoints.getItem(1);
    var p3 = poly.animatedPoints.getItem(2);
    var x1 = p1.x * u + p2.x * t;
    var y1 = p1.y * u + p2.y * t;
    var x2 = p2.x * u + p3.x * t;
    var y2 = p2.y * u + p3.y * t;
    tangentLine.setAttribute("x1", x1);
    tangentLine.setAttribute("y1", y1);
    tangentLine.setAttribute("x2", x2);
    tangentLine.setAttribute("y2", y2);
    tangentPoint.setAttribute("cx", x1 * u + x2 * t);
    tangentPoint.setAttribute("cy", y1 * u + y2 * t);

🕑 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.