Prepared by Yauheni Hladkiy
<canvas> is HTML5 element can be used to draw graphics via scripting in JavaScript.
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
<head>
<script>
function draw(){
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
}
</script>
</head>
<body onload="draw();">
</body>
fillRect(x, y, width, height);
strokeRect(x, y, width, height);
clearRect(x, y, width, height);
Steps for make shapes using paths:
function draw() {
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
ctx.moveTo(110,75);
ctx.arc(75,75,35,0,Math.PI,false); // Mouth (clockwise)
ctx.moveTo(65,65);
ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
ctx.moveTo(95,65);
ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
ctx.stroke();
}
fillStyle = color //sets the style used when filling shapes.
strokeStyle = color //sets the style for shapes' outlines.
ctx.fillStyle = 'orange';
ctx.fillStyle = '#FFA500';
ctx.fillStyle = 'rgb(255, 165, 0)';
ctx.fillStyle = 'rgba(255, 165, 0, 1)';
ctx.globalAlpha = 0.2;
Example
lineWidth = value;
lineCap = type; // butt, round, square
lineJoin = type; // round, bevel, miter
createLinearGradient(x1, y1, x2, y2);
createRadialGradient(x1, y1, r1, x2, y2, r2);
gradient.addColorStop(position, color);
var img = new Image(); // Create new img element
img.src = 'myImage.png'; // Set source path
img.onload = function() {
ctx.drawImage(img, 0, 0);
}