+ 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

11th Mar 2021, 8:49 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
33 Answers
+ 9
Oh OK
11th Mar 2021, 9:36 AM
Coder Kay
Coder Kay - avatar
+ 8
Wait
11th Mar 2021, 11:23 AM
Coder Kay
Coder Kay - avatar
11th Mar 2021, 9:28 AM
A͢J
A͢J - avatar
+ 6
https://code.sololearn.com/WlHr5XU6CLwY/?ref=app
11th Mar 2021, 9:53 AM
Papa Penguin
+ 5
𝕂𝕒𝕪 That is not what I needed 😔
11th Mar 2021, 9:31 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 5
Dark Stream Oh! You want painting app right
11th Mar 2021, 9:34 AM
Coder Kay
Coder Kay - avatar
+ 5
Yes......
11th Mar 2021, 9:34 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 5
I will send you after some time
11th Mar 2021, 9:35 AM
Coder Kay
Coder Kay - avatar
+ 5
Ok,now I have edited that code as a easy way for u all to understand
11th Mar 2021, 9:35 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 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😇
11th Mar 2021, 9:38 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 4
What do you want?
11th Mar 2021, 9:32 AM
Coder Kay
Coder Kay - avatar
11th Mar 2021, 9:32 AM
A͢J
A͢J - avatar
+ 4
Dark Stream Do you want like that we do painting?
11th Mar 2021, 9:33 AM
A͢J
A͢J - avatar
+ 4
Oh OK ☺
11th Mar 2021, 9:39 AM
Coder Kay
Coder Kay - avatar
+ 4
visph Could u find a solution to my problem 🤨
11th Mar 2021, 11:22 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 4
Ok😀
11th Mar 2021, 11:25 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 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);
11th Mar 2021, 11:32 AM
visph
visph - avatar
+ 4
visph Your answer was perfect and worked well,Thank u😇👍
11th Mar 2021, 12:05 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 4
May I have a look of the working app
11th Mar 2021, 1:22 PM
Ernest Brayce
Ernest Brayce - avatar
+ 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
11th Mar 2021, 8:58 AM
Coder Kay
Coder Kay - avatar