js canvas
js canvas
500px
(0,0) is the (500,0) is the top
top left corner right corner of
of the canvas 300px the canvas
(400, 100)
(100, 100)
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(100, 200);
ctx.lineTo(200, 100);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(100, 200);
ctx.lineTo(200, 100);
ctx.closePath();
ctx.stroke();
lineJoin = "round"|"bevel"|"miter"
setLineDash(pattern)
Ex: setLineDash([3, 8, 10, 2])
...
ctx.closePath();
ctx.fill();
ctx.stroke();
...
ctx.closePath();
ctx.stroke();
ctx.fill();
Example:
ctx.beginPath();
ctx.arc(100, 75, 50, 0, Math.PI * 2);
ctx.clip();
ctx.fillStyle = 'blue';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'orange';
ctx.fillRect(0, 0, 100, 100);
img.onload = function() {
ctx.drawImage(img, 100, 50);
};
Question: Is it neccessary to set img.src before img.onload?
strokeText fillText
73 AC2070: Web Design & Programming
Đào Trung Kiên @ MICA Institute & Dept. of Comm. Eng., SEEE, Hanoi Univ. of Science and Technology
Shadows
Use the following properties:
shadowColor
shadowBlur
shadowOffsetX
shadowOffsetY
window.requestAnimationFrame(draw); ctx.fill();
}, 50); ctx.restore();
}
// first frame
draw();