Canvas
- Canvas Introduction
- Canvas Draw Rectangles
- Canvas Draw Lines
- Canvas Draw Bezier
- Canvas Draw Quadratic
- Canvas Draw Arc
- Canvas Draw Paths
- Canvas Manipulating Images
- Canvas Linear Gradients
- Canvas Radial Gradients
- Canvas Text
- Canvas Pattern
- Canvas Shadow
- Canvas States
- Canvas Translate
- Canvas Rotate
- Canvas Scale
- Canvas Transform
- Canvas Composition
Canvas Draw Quadratic
Photo Credit to CodeToFun
🙋 Introduction
The HTML canvas element provides a powerful way to create dynamic graphics and animations directly within web pages. Among its features is the ability to draw quadratic curves, which can be used to create smooth, flowing shapes and lines.
In this guide, we'll explore how to draw quadratic curves on the HTML canvas.
💡 Syntax
To draw a quadratic curve on the canvas, you'll use the quadraticCurveTo() method. Here's the basic syntax:
context.quadraticCurveTo(cp1x, cp1y, x, y);
🧰 Attributes
- cp1x, cp1y: The coordinates of the control point that defines the curve's shape.
- x, y: The coordinates of the end point of the curve.
📄 Example
Let's draw a simple quadratic curve on the canvas:
const canvas = document.getElementById('myCanvas');
const context = canvas.getContext('2d');
// Start the path
context.beginPath();
context.moveTo(20, 100); // Move to the starting point
context.quadraticCurveTo(100, 20, 200, 100); // Draw quadratic curve
context.stroke(); // Draw the curve
🧠 How it works?
In this example, we start a path, move to the starting point (20, 100), and then draw a quadratic curve to the point (200, 100) with the control point (100, 20).
🎉 Conclusion
Drawing quadratic curves on the HTML canvas adds a level of sophistication and fluidity to your graphical creations.
By understanding the syntax and usage of the quadraticCurveTo() method, you can leverage the power of quadratic curves to design visually stunning graphics and animations for your web projects.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (Canvas Draw Quadratic), please comment here. I will help you immediately.