HTML Canvas Quadratic curve

Introduction

HTML5 Quadratic curves are defined by the context point, a control point, and an ending point:

context.quadraticCurveTo(controlX, 
                         controlY, 
                         endingPointX,        
                         endingPointY); 
                         

View in separate window

<html>
    <head>
        <script>
            window.onload = function(){
                var canvas = document.getElementById("myCanvas");
                var context = canvas.getContext("2d");
                //from  w  ww  .j  a  va 2s  .  c o  m
                context.lineWidth = 10;
                context.strokeStyle = "black"; // line color
                context.moveTo(100, canvas.height - 50);
                context.quadraticCurveTo(canvas.width / 2, 
                                         -50, 
                                         canvas.width - 100, 
                                         canvas.height - 50);
                context.stroke();
            };
        </script>
    </head>
    <body>
        <canvas id="myCanvas" width="600" height="250" style="border:1px solid black;">
        </canvas>
    </body>
</html>



PreviousNext

Related