HTML5 Game - Canvas Quadratic Curve

Introduction

Quadratic curves have more flexibility.

Note

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

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

The curvature of a Quadratic curve is defined by three characteristic tangents.

Demo

ResultView the demo in separate window

<html>
    <head>
        <script>
            window.onload = function(){
                let canvas = document.getElementById("myCanvas");
                let context = canvas.getContext("2d");
                // w  ww.ja v a 2 s .com
                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>

Related Topics