This article introduces the sample code for drawing emoticons on canvas and shares it with everyone. The details are as follows:
Draw cartoon smiley face
var canvas = document.getElementById('canvas');var context = canvas.getContext('2d');//Draw a face and set the fill color of the face to '#fff'context.fillStyle = '#fff';context. beginPath();context.arc(150, 150, 60, 0, Math.PI*2);context.closePath();context.fill();//Draw the eyes and set the fill color of the eyes to 'rgb(0, 0, 0)'context.fillStyle = 'rgb(0, 0) , 0)';context.beginPath();context.arc(130, 130, 8, 0, Math.PI*2);context.closePath();context.fill();context.fillStyle = 'rgb(0, 0, 0)';context.beginPath();context.arc(170, 130, 8, 0, Math.PI*2);context.closePath();context.fill();// Draw the mouth and set the fill color of the mouth to 'rgba(255, 0, 0, 0.8)'context.fillStyle = 'rgba(255, 0, 0, 0.8)';context.beginPath();context.arc(150, 160, 25, Math.PI, Math.PI*2, true);context.closePath();context.fill();//Draw blush, set the blush line color to 'pink', and the line width to 5context.beginPath();context.moveTo(95, 152);context .lineTo(110, 150);context.moveTo(190, 150);context.lineTo(205, 152);context.closePath();context.lineWidth = 5;context.strokeStyle = 'pink';context.stroke();Make emoticons
var canvas = document.getElementById('canvas');var context = canvas.getContext('2d');var image = new Image();image.src= 'https://ke.qq.com/classroom/assets /lib/img/canvas-expression-base.png';image.onload = function(){ context.drawImage(image, 50, 110, 200, 200);}context.font = '30px arial';context.fillText('Today's me', 20, 50);context.font = '40px arial';context.fillText('Still as handsome!', 20 , 90);The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope everyone will support VeVb Wulin Network.