Define a radial gradient with the createRadialGradient() method and fill the shape with the gradient:
//add a radial gradient
var grdCenterX = 260;
var grdCenterY = 80;
var grd = context.createRadialGradient(grdCenterX, grdCenterY, 10, grdCenterX, grdCenterY, 200);
grd.addColorStop(0, "#8ED6FF"); // light blue
grd.addColorStop(1, "#004CB3"); // dark blue
context.fillStyle = grd;
context.fill();
Set the line width and stroke the cloud:
// set the line width and stroke color
context.lineWidth = 5;
context.strokeStyle = "#0000ff";
context.stroke();
};
Embed the canvas tag inside the body of the HTML document:
To draw a fluffy cloud using the HTML5 canvas API, we can connect several Bezier curves to form the perimeter of the cloud shape. To create the illusion of a bulbous surface, we can create a radial gradient using the createRadialGradient() method, set the gradient colors and offsets using the addColorStop() method, set the radial gradient as the fill style using fillStyle, and then apply the gradient using fill().