+ 6
What is wrong in my code ! (Canvas[Help])[Solved]
Here is a sample code...I want that to act as a paint app,but my code doesn't work so please explain me the solution for this https://code.sololearn.com/WVlMYsunTnTH/?ref=app
33 Answers
+ 9
Oh OK
+ 8
Wait
+ 7
Dark Stream
I already gave you a solution then why this question again
https://code.sololearn.com/WmH1uBQRgjIV/?ref=app
https://www.sololearn.com/Discuss/2720987/?ref=app
+ 6
https://code.sololearn.com/WlHr5XU6CLwY/?ref=app
+ 5
𝕂𝕒𝕪 That is not what I needed 😔
+ 5
Dark Stream
Oh! You want painting app right
+ 5
Yes......
+ 5
I will send you after some time
+ 5
Ok,now I have edited that code as a easy way for u all to understand
+ 5
I have re edited the code,as for easier understanding....what I want is to it act as a paint app...but it doesn't work....so I want the solution for it😇
+ 4
What do you want?
+ 4
Dark Stream
Ok.
+ 4
Dark Stream
Do you want like that we do painting?
+ 4
Oh OK ☺
+ 4
visph Could u find a solution to my problem 🤨
+ 4
Ok😀
+ 4
you need to use touch events (mousemove doesn't fire with touch devices):
function paint(event){
for (var t of event.touches) {
touch.x = t.clientX;
touch.y = t.clientY;
drawCircle();
}
}
canvas.addEventListener('touchstart',paint);
canvas.addEventListener('touchmove',paint);
canvas.addEventListener('touchend',paint);
+ 4
visph Your answer was perfect and worked well,Thank u😇👍
+ 4
May I have a look of the working app
+ 3
window.onload = function(){
const canvas =
document.getElementById('canvas1');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
window.addEventListener('resize',function(){
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
const touch = {
x:null,
y:null,
};
canvas.addEventListener('click',function(event){
touch.x = event.x;
touch.y = event.y;
drawCircle();
});
/*
canvas.addEventListener('mousemove',function(event){
touch.x = event.x;
touch.y = event.y;
drawCircle();
});
*/
function drawCircle() {
ctx.fillStyle = '#fff';
ctx.strokeStyle = '#f1f';
ctx.lineWidth = 5;
ctx.beginPath();
ctx.arc(touch.x,touch.y, 5, 0, Math.PI * 2);
ctx.stroke();
ctx.fill();
}
}
Now Run this code.
when our window is load then code is run.
without any error onload is an event in js