Canvas Draw Bezier
How to Draw a Bezier
To draw a bezier, follow these steps
- canvas - Assigning the canvas element to a variable.
- ctx - Assigning the 2d rendering context to another variable by calling the
getContext('2d')
method. - beginPath() - Use
beginPath()
canvas method to start a new path by emptying the list of sub-paths. - moveTo() - Use
moveTo()
canvas method to begin a new sub-path at the point specified by the given (x, y) coordinates. - bezierCurveTo() - Use
bezierCurveTo()
canvas method to add a cubic Bézier curve to the current sub-path. - stroke() - Use
stroke()
canvas method to stroke (outline) the current or given path with the currentstrokeStyle
. The defaultstrokeStyle
is 'black'.
Example
HTML Online Editor
<!DOCTYPE html>
<html lang="en-US">
<body>
<canvas id="point" width="230" height="150">
Your browser does not support the canvas element.
</canvas>
<script>
var canvas = document.getElementById('point');
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.moveTo(5, 5);
ctx.bezierCurveTo(100,150, 200,10, 220,140);
ctx.stroke();
</script>
</body>
</html>
Syntax
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
Attributes Value
Value | Explanation |
---|---|
cp1x | Specifies the x-axis coordinate of the first control point. |
cp1y | Specifies the y-axis coordinate of the first control point. |
cp2x | Specifies the x-axis coordinate of the second control point. |
cp2y | Specifies the y-axis coordinate of the second control point. |
x | Specifies the x-axis coordinate of the end point. |
y | Specifies the y-axis coordinate of the end point. |
Reminder
Hi Developers, we almost covered 93% of Canvas Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in Canvas.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.