Writing in pencil on the photo would involve several steps, to upload/display the photo, etc. Adding more colors makes it again more difficult, to get you started with the drawing, here are some codes:
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
let drawing = false;
// Function to start drawing
canvas.addEventListener('mousedown', (event) => {
drawing = true;
ctx.beginPath();
ctx.moveTo(event.offsetX, event.offsetY);
});
// Function to draw on the canvas
canvas.addEventListener('mousemove', (event) => {
if (drawing) {
ctx.lineTo(event.offsetX, event.offsetY);
ctx.stroke();
}
});
// Function to stop drawing
canvas.addEventListener('mouseup', () => {
drawing = false;
ctx.closePath();
});
// Optionally, clear the canvas
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
let drawing = false;
// Function to start drawing
canvas.addEventListener('mousedown', (event) => {
drawing = true;
ctx.beginPath();
ctx.moveTo(event.offsetX, event.offsetY);
});
// Function to draw on the canvas
canvas.addEventListener('mousemove', (event) => {
if (drawing) {
ctx.lineTo(event.offsetX, event.offsetY);
ctx.stroke();
}
});
// Function to stop drawing
canvas.addEventListener('mouseup', () => {
drawing = false;
ctx.closePath();
});
// Optionally, clear the canvas
function clearCanvas() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
}
Statistics: Posted by Euol — Tue Aug 06, 2024 8:15 am