CANVAS JavaScript Drawing App 🎨 | Draw ● Undo ● Erase ● Colors | Full HTML5 Canvas App Tutorial

  Рет қаралды 63,637

BananaCoding

BananaCoding

Күн бұрын

Пікірлер: 138
@BananaCoding
@BananaCoding 3 жыл бұрын
The Timelaps :) 00:00 - 00:42 Introduction 00:43 - 03:09 Building the HTML construct 03:10 - 08:10 Styling with CSS 08:11 - 10:46 JS define Canvas variables and settings 10:47 - 17:03 Drawing functions 17:04 - 20:20 Changing colors + color picker + pen size 20:21 - 21:55 Clear full canvas field 21:56 - 27:20 Undo paths and writings / drawings 27:21 Outro
@ienvyzerefjod
@ienvyzerefjod 3 жыл бұрын
How to draw on mobile using touch
@w3cprogramming678
@w3cprogramming678 Жыл бұрын
how can add redo button?
@arshiaiscool4069
@arshiaiscool4069 3 жыл бұрын
one of the best tutorials i have ever seen ,nice job!!
@BananaCoding
@BananaCoding 3 жыл бұрын
Thanks mate :)!
@emausdetiquicia6636
@emausdetiquicia6636 11 ай бұрын
I've followed all your canvas tutorials and learnt a lot. Thanks for all the effort you put on those.
@johnconley4955
@johnconley4955 2 жыл бұрын
The first to put in a 'icon' link...found how to do this myself a few weeks ago, always good to do, makes it more personal...good vid
@Alexis-gf6kf
@Alexis-gf6kf 3 жыл бұрын
Hello, your tutorial is just perfect, exactly what I wanted, thank you very much and good luck for the future !
@BananaCoding
@BananaCoding 3 жыл бұрын
Thank you for that nice words, means a lot to me! :)
@Alexis-gf6kf
@Alexis-gf6kf 3 жыл бұрын
@@BananaCoding Hello, you're welcome, but do you know a system to make an eraser (not to erase everything but just erase around the cursor) to implement in your javascript? Thank you in advance for your reply !
@BananaCoding
@BananaCoding 3 жыл бұрын
Hey, sorry for the late answer. One way for erasing is simply to draw with the color white over the board, so it looks like an eraser :)!
@Alexis-gf6kf
@Alexis-gf6kf 3 жыл бұрын
@@BananaCoding Hello, thank you for your answer but, in fact, I would like to put an image in the background and be able to draw it, a bit like a painting. This is why the option to draw in white could not work. PS: Do you know a way to put an image or a pdf document in the background instead of white? Thank you for your response and sorry for any questions! Good continuation (Sorry for my English, I am French and I use Google Translate)
@BananaCoding
@BananaCoding 3 жыл бұрын
@@Alexis-gf6kf For the eraser, I found an good article on Stackoverflow: stackoverflow.com/questions/25907163/html5-canvas-eraser-tool-without-overdraw-white-color. I also already did an other video about canvas and images : kzbin.info/www/bejne/fGi4n3SLa5irn7s Hope this can help you! :)
@nuraktar7815
@nuraktar7815 3 жыл бұрын
this is the best video in the youtube for drawing app ... thanks 4 the video
@razarukhsar8479
@razarukhsar8479 Жыл бұрын
Yeye !I will do this Thankyo I'm glad to find your chennel really appreciate ✨good luck
@tech_reforcae_mn
@tech_reforcae_mn Жыл бұрын
Man, this tutorial is amazing, congrats!
@AbdulWahab-pc5zl
@AbdulWahab-pc5zl 3 жыл бұрын
Thanks for the tutorial it was amazing but one extra thing I need is to add an option for background images can you help me out or anyone from the worthy audience
@GFirehold
@GFirehold 2 жыл бұрын
This tutorial is awesome. Very clear and easy to follow. Maybe you can answerr me a question, is there an additional property to add, that the lines are smoother? And would it be hard to add an eraser-tool? And my most important question: whats the name of your VS Theme, i really like the colors :) Many Greets!
@joelfigueroa7127
@joelfigueroa7127 3 жыл бұрын
one of the best tutorials out there! keep going pal!
@sanchitbhasin4098
@sanchitbhasin4098 3 жыл бұрын
very well explained 👏
@Bintang240196
@Bintang240196 Ай бұрын
This tutorial is awesome, i have implemented it in one of my projects. The only problem i got is, the touch event doesn't work on my Samsung Tablet running chrome. Can you check what is wrong?
@hamzaaboulas3845
@hamzaaboulas3845 3 жыл бұрын
i like it , and it worked for me , i had to tweek things alittle bit but its clear what he is saying , Thank you
@codemagic2487
@codemagic2487 3 жыл бұрын
The video is very good and helpful, exactly what I was looking for ! Good luck!
@BananaCoding
@BananaCoding 3 жыл бұрын
Thanks mate, nice to hear that! Wish you too.
@hadi.edh7
@hadi.edh7 Жыл бұрын
You are amazing man!! very enjoyable tutorial❤
@sweethomes674
@sweethomes674 Жыл бұрын
Excellent techniques 😊
@bayzidhossain7959
@bayzidhossain7959 2 жыл бұрын
sir can I save the drawing using save button ? If i do than please give us a tutorial on it. Thank You
@NoBrainerLanguages
@NoBrainerLanguages 2 жыл бұрын
Trying to come up with my own and it's the very first time in all these years that I can't get the line to spawn from the cursor. It draws anywhere bu from mouse position and I've been using the same simple logic since the ol' good VB6 lol. The offset is not being calculated correctly and I'm pretty much using the same basic principle this video and any other tutorial show. [EDIT FOR THE SOLUTION] first of all, the version where I edited canvas position and size using CSS and setting position as absolute messed up the entire tracking of the mouse cursor on the canvas. I created a second version with a canvas whose size was given in the HTML tag with integer numbers only (namely 800 and 600) and the same code from the first attempt worked. However, in order to have the same effect as seen in this video, I had to move the "moveTo" method to the mousedown event and leave the "lineTo" method in the scope of the function being called by the onmousemove event. In other words, positioning of the canvas and units used will hurt the accuracy. In order to have a line that follows the mouse as freehand style (not a straight line from point A to point B) we must separate the "moveTo" and "lineTo" methods. I even tried, just to make sure, call both in the onmousedown event and it fails again. "lineTo" AND canvas.stroke methods must be BOTH in the onmousemove event, conditioned by a boolean flag that confirms the mousedown event is taking place (meaning user is trying to draw). Unless, of course you want the line to only be visible when the mouseout takes place instead of a realtime line being drawn. In that case you want to delay the result, just call the canvascontext.stroke() in the onmouseout event. If you call it in the onmousedown event, you'll have an even longer delay as the line you just drew will only show when you start a mousedown event to start a new line. The biggest problem, in conclusion, is that if you want to create a nice drawing tool, the positioning of the canvas and other elements of your page will give you an enormous headache.
@jurygans719
@jurygans719 3 жыл бұрын
Hello, You have a bag in the undo_last function. -> function undo_last() { if(index
@BananaCoding
@BananaCoding 3 жыл бұрын
Hello, thanks for your advice!
@luuufe8484
@luuufe8484 2 жыл бұрын
How do I create a redo function?
@thecsspage5603
@thecsspage5603 2 жыл бұрын
That's something I was looking for 🔥🔥🔥 thanks
@BananaCoding
@BananaCoding 2 жыл бұрын
Thanks, nice to hear that!
@LunchboxdadioMusic
@LunchboxdadioMusic 3 жыл бұрын
With newer javascript you may need to add window.change_color = change_color; in your javascript file to get the HTML onclick to work
@GeNoZiKs
@GeNoZiKs 2 жыл бұрын
Hey ! The color buttons don't seem to work for me, in which line of the javascrisp file I should put this please ? (Complete beginner here sorry !)
@nileshvishwakarma118
@nileshvishwakarma118 3 жыл бұрын
Bro, this video is awesome. Can you add fill button which can fill the drawing with colour?
@andreasofficiall
@andreasofficiall 2 жыл бұрын
Now I realise I know nothing about Javascript XD, no but really amazing video! Thanks for the tutorial :)
@BananaCoding
@BananaCoding 2 жыл бұрын
Thank you! :)
@zahidshaikh3122
@zahidshaikh3122 2 жыл бұрын
Great content, Thanks a lot!
@DeveloperRimon
@DeveloperRimon 3 жыл бұрын
Good job man!!!!
@tehyanyang6959
@tehyanyang6959 2 жыл бұрын
lovely video ive learned alot from this thank you :)
@BananaCoding
@BananaCoding 2 жыл бұрын
Thank you :)!
@sadsadsad5000
@sadsadsad5000 2 жыл бұрын
based, thanks for the video
@whome4860
@whome4860 3 жыл бұрын
you are the best ... thanks
@twiztidstaticx7618
@twiztidstaticx7618 3 жыл бұрын
Great Tutorial. I can not get the image to save though. Can you show how to save to local storage on mobile?
@halfcookedramen
@halfcookedramen 2 жыл бұрын
try the getDataURL() property. This transforms the canvas into a "data:image/png:base64,iViVBORw0KGgoAAAANSUhEUgAAAZ..." link. This can be read by your browser and put in localStorage. Then, onload, try placing the image in the canvas.
@supermauz
@supermauz 3 жыл бұрын
best tutorial Ever!
@BananaCoding
@BananaCoding 3 жыл бұрын
Thank you!!
@eguchiyuuki
@eguchiyuuki Жыл бұрын
great!
@Vlada97my
@Vlada97my 2 жыл бұрын
could this be done so it could be like an interactive white board? i'm aiming to do something like thous drawing online games.
@chigozieobialor1245
@chigozieobialor1245 2 жыл бұрын
I've got a link 4U :) m.kzbin.info/www/bejne/eKOXppSOfdeCesk
@genaromartinezcarrer
@genaromartinezcarrer Жыл бұрын
Amazing tutorial! but I have a problem... When I try to create the undo function it doesn't work for me, the console gives me this error "Failed to execute 'putImageData' on 'CanvasRenderingContext2D': parameter 1 is not of type 'ImageData" What can I do to solve this?
@larryshamala8929
@larryshamala8929 2 жыл бұрын
hi, thank you for your good work. i request you help us with your full codes for the tutorials so that we may understand better
@BananaCoding
@BananaCoding 2 жыл бұрын
Hi, thanks sir, here the code for you: codepen.io/BananaCoding/pen/mdrGjpL
@sanjayr.prajapati3496
@sanjayr.prajapati3496 3 жыл бұрын
Helpful. Can you make a video on drawing shapes like square and circle?
@BananaCoding
@BananaCoding 3 жыл бұрын
Thanks for that! I already did a video series about canvas where I did that. Here is the first video: kzbin.info/www/bejne/pmmbo4GZoMiWo8k
@sanjayr.prajapati3496
@sanjayr.prajapati3496 3 жыл бұрын
@@BananaCoding Thanks for the reply. But what I want is that when user starts drawing square, the drawing effect should been seen. Means from mouseDown to mouseUp square should scale. I hope you understand what I am trying to say.
@BananaCoding
@BananaCoding 3 жыл бұрын
Yes, I think I know what you mean. I found this on CodePen, might help you maybe: codepen.io/AllenT871/pen/GVyXKp (use on computer)
@kvnp9683
@kvnp9683 2 жыл бұрын
How to check the drawn diagram with parameters and return reviews based on it??? Please Help!!!
@jonesmichael7799
@jonesmichael7799 3 жыл бұрын
Great tutorial! I have one problem, the touch event isn't working on my mobile devices and I've tested on multiple browsers. Any advice?
@BananaCoding
@BananaCoding 3 жыл бұрын
Thanks! Most of the actions use the HTML attribute „onClick“, maybe try also „onTouch“ :)
@BananaCoding
@BananaCoding 3 жыл бұрын
Here is the code, it works mobile: codepen.io/BananaCoding/pen/mdrGjpL
@hamidomar350
@hamidomar350 3 жыл бұрын
@@BananaCoding Yeaa!!! good shit XD thanks @Jones Michael for asking this. I don't know crap about web dev and wouldn't have been able to solve this on my own...
@techiejay2k23
@techiejay2k23 3 жыл бұрын
Will you please tell how to write code for working of Redo button?
@BananaCoding
@BananaCoding 3 жыл бұрын
You can save the deleted Item in another array. If you click on the button, take the item and „redraw“ it!
@techiejay2k23
@techiejay2k23 3 жыл бұрын
@@BananaCoding Thank you
@luuufe8484
@luuufe8484 2 жыл бұрын
@@techiejay2k23 You got it?
@techiejay2k23
@techiejay2k23 2 жыл бұрын
@@luuufe8484 Yes, but it's not working completely fine
@amitsolanki9363
@amitsolanki9363 Жыл бұрын
How can i save canvas to image that uses s3 image it give me error Uncaught SecurityError: Failed to execute ‘getImageData’ on ‘CanvasRenderingContext2D’: The canvas has been tainted by cross-origin data
@ThaoNguyen-lj6qn
@ThaoNguyen-lj6qn 2 жыл бұрын
Is there a way to make this detectable witih a tablet pen?
@markystudio14
@markystudio14 3 жыл бұрын
is it possible to create a multiple layer of canvas with a transparent background? what i mean is what we already see to other software that you can sketch with multiple layer of drawings? just like, overlay, line-art, color art, underlay, layers. by the way this is grate! keep up
@markystudio14
@markystudio14 3 жыл бұрын
i noticed when i add the touch stop event , the touchstart or touchend somewhere, is not working on my tablet. why is that happening?
@BananaCoding
@BananaCoding 3 жыл бұрын
Maybe this helps you, here is the code: codepen.io/BananaCoding/pen/mdrGjpL
@mesmartboy1985
@mesmartboy1985 2 жыл бұрын
What about erase??
@xVroft
@xVroft 2 жыл бұрын
can i somehow import an black and white picture to this so you could color it ?
@ZeroChenKun
@ZeroChenKun Жыл бұрын
May I get the source code, after watching this video, I want to start it myself,but GOT some .....,
@BrandonPetaccio
@BrandonPetaccio 3 жыл бұрын
How can we now save the image? specifically, save it to a mysql database?
@mayanktripathi4u
@mayanktripathi4u 3 жыл бұрын
Did you got how to save the canvas image? If so please do share.
@BananaCoding
@BananaCoding 3 жыл бұрын
Hey you can save it with this function: function Save(a) { var img = canvas.toDataURL('image/png'); a.href = img; } Just bind the function to a button with the attribute onClick=„Save(this)“
@twiztidstaticx7618
@twiztidstaticx7618 3 жыл бұрын
@@BananaCoding I can not get the image to save using this?
@waiyingcheung2639
@waiyingcheung2639 3 жыл бұрын
@@twiztidstaticx7618 me too, how can you solve this?
@jakubpetrik4997
@jakubpetrik4997 3 жыл бұрын
@@BananaCoding Can someone solved it ?
@ramlaaal
@ramlaaal 2 жыл бұрын
what theme are you using,
@Gs0c
@Gs0c 3 жыл бұрын
what is writed on the "integrity" line?
@abubuckerm4934
@abubuckerm4934 3 жыл бұрын
It is really nice job. How can we add Redo option?
@halfcookedramen
@halfcookedramen 2 жыл бұрын
i guess add another list with everything in there? don't take anything out of the list, just navigate it.
@rosamariajerez2513
@rosamariajerez2513 3 жыл бұрын
How can i draw and crop one irregular each of a image with JS, JQuery or python? thank u!!
@rosamariajerez2513
@rosamariajerez2513 3 жыл бұрын
i want create a image, start of other image... i was find this for circle, square, triangle etc... but i don´t get for irregular forms
@platinum5501
@platinum5501 3 жыл бұрын
Hello BananaCoding, so the canvas color change drawing for the onClick doesn't work. Can you help me out?
@BananaCoding
@BananaCoding 3 жыл бұрын
Hi! Which error message do you have in the console?
@platinum5501
@platinum5501 3 жыл бұрын
@@BananaCoding Oh, nevermind, i was able to have the problem fixed. I didn't save the project! But still thanks for responding! Also, great tutorials! :D
@BananaCoding
@BananaCoding 3 жыл бұрын
Nice to hear, thank you! :)
@haseebbbb
@haseebbbb 2 жыл бұрын
its not letting me draw
@1Clashio
@1Clashio 3 жыл бұрын
Hello! Thank you everything went well. I changed the width in JavaScript: canvas.width = 800; But I need that canvas in a different position so I added to the css file .field { position: absolute; left: 330px; top: 500px; } Now the problem is that when I draw in a point inside the canvas it draws like 150px bellow my mouse. Can i fix that so it could draw exactly where I click my mouse?
@BananaCoding
@BananaCoding 3 жыл бұрын
Thank you! I know what you mean, don’t try to work with position: absolute. Try to change the position with Flex layouts or margin!
@1Clashio
@1Clashio 3 жыл бұрын
@@BananaCoding Okay thank you for replying. I'm gonna search up how to do that
@1Clashio
@1Clashio 3 жыл бұрын
@@BananaCoding I changed the position with margin it works well when I'm at the top of the window, but if I scroll a little bit down the drawing will be off. Now i need to be at the top of the page to be able to draw without it being a few centimeters off. And that doesn't work for me
@NoBrainerLanguages
@NoBrainerLanguages 2 жыл бұрын
I suspected that was the issue. After all these years, HTML doesn't have a decent standardized way to measure things, so drawings and fonts are the worst dev nightmare to finally set up.
@1Clashio
@1Clashio 2 жыл бұрын
@@NoBrainerLanguages Thank you, for your help!
@vishaliniraja
@vishaliniraja 3 жыл бұрын
Haii your video superb can you share the code please
@BananaCoding
@BananaCoding 3 жыл бұрын
Thanks, sure codepen.io/BananaCoding/pen/mdrGjpL
@KhaledBis-q4e
@KhaledBis-q4e 25 күн бұрын
Arabic support is possible, good luck
@레오-v2g
@레오-v2g 3 жыл бұрын
What is right panel execute canvas?
@BananaCoding
@BananaCoding 3 жыл бұрын
Hey, can you explain what you mean?
@레오-v2g
@레오-v2g 3 жыл бұрын
@@BananaCoding Wow. Never mind. I was mistaken.
@sibanandaparida4878
@sibanandaparida4878 3 жыл бұрын
What theme do you use??
@BananaCoding
@BananaCoding 3 жыл бұрын
One Dark Pro
@sibanandaparida4878
@sibanandaparida4878 3 жыл бұрын
By the way such an amazing explanation brother…Keep it up 👍🏼
@BananaCoding
@BananaCoding 3 жыл бұрын
Thank you, that means a lot to me :)!
@russell_talent
@russell_talent 2 жыл бұрын
@@BananaCoding and what font and size bolt? :) theme One Dark Pro slightly different
@tyresezaid6212
@tyresezaid6212 3 жыл бұрын
Good. I wait for love from you 💝💖
@BananaCoding
@BananaCoding 3 жыл бұрын
Thank you
@sonnguyen1197
@sonnguyen1197 3 жыл бұрын
How can we remove line in your canvas?
@BananaCoding
@BananaCoding 3 жыл бұрын
One easy way is to overwrite with white color
@DUYNguyen-kn6xg
@DUYNguyen-kn6xg 3 жыл бұрын
set globalCompositeOperation = 'destination-out', this basically turns your context2D into an eraser
@ayushrautela8567
@ayushrautela8567 2 жыл бұрын
@@DUYNguyen-kn6xg can you please help I am not able to implement it🙏
@yt-spikegaming7394
@yt-spikegaming7394 2 жыл бұрын
where is erase?
@nayabmannan6470
@nayabmannan6470 2 жыл бұрын
source code?
@larryshamala8929
@larryshamala8929 2 жыл бұрын
I am unable to draw.
@NG15427
@NG15427 2 жыл бұрын
it's a bad habit to add javascript in your html... you should have added all event bindings in your js file.
@BananaCoding
@BananaCoding 2 жыл бұрын
Yes, this is just for demo purposes
@divyjain490
@divyjain490 3 жыл бұрын
can you give the code link
@BananaCoding
@BananaCoding 3 жыл бұрын
Sure, codepen.io/BananaCoding/pen/mdrGjpL
@divyjain490
@divyjain490 3 жыл бұрын
@@BananaCoding can you give a code of the same in react and node where changes made on one browser reflect on another with socket and a eraser and basic shapes ,it will be very helpful if you can provide that
@bhaitabahi786
@bhaitabahi786 2 жыл бұрын
sir can u upload the source code pls
@BananaCoding
@BananaCoding 2 жыл бұрын
Sure, here you find it: codepen.io/BananaCoding/pen/mdrGjpL
@naturessound4672
@naturessound4672 2 жыл бұрын
Please send source code
@haseebbbb
@haseebbbb 2 жыл бұрын
send source code
@Phongtutorial
@Phongtutorial Жыл бұрын
Source Code
@webdbase
@webdbase Жыл бұрын
See the anwser to Bhai tabahi
HTML5 Canvas CRASH COURSE for Beginners
51:26
Franks laboratory
Рет қаралды 217 М.
Girl, dig gently, or it will leak out soon.#funny #cute #comedy
00:17
Funny daughter's daily life
Рет қаралды 14 МЛН
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 37 МЛН
CSS Tips And Tricks I Wish I Knew Before
12:12
Lama Dev
Рет қаралды 477 М.
Стрелочные функции JavaScript. JavaScript function 2021
22:21
WebDev с нуля. Канал Алекса Лущенко
Рет қаралды 28 М.
Учим HTML5 Canvas за 30 минут!
36:56
Хауди Хо™ - Просто о мире IT!
Рет қаралды 212 М.
Award Winning Animation With Only 20 Lines Of CSS?
6:59
Hyperplexed
Рет қаралды 1,8 МЛН
Please stop using px for font-size.
15:18
Coder Coder
Рет қаралды 157 М.
Learn HTML5 Canvas By Creating A Drawing App | HTML Canvas Tutorial
19:43
HTML5 Canvas API Crash Course
53:56
Traversy Media
Рет қаралды 191 М.
Incredible scroll-based animations with CSS-only
32:23
Kevin Powell
Рет қаралды 432 М.