Today, You are going to see the power of HTML5 and Javascript and I’m going to show you, step by step, how to create the Great DrawSomething application in Javascript.
DrawSomething JS
Ready?!?! so lets go.
The first thing we’re going to learn is how to draw inside your browser:
HTML5 has a new element called Canvas, to add a canvas inside your html, you just need to copy this code inside the html page:
<canvas id=”board” class=”board” ></canvas>
To draw inside this canvas with the mouse, we need to listen to three mouse events:
Ready?!?! so lets go.
The first thing we’re going to learn is how to draw inside your browser:
HTML5 has a new element called Canvas, to add a canvas inside your html, you just need to copy this code inside the html page:
<canvas id=”board” class=”board” ></canvas>
To draw inside this canvas with the mouse, we need to listen to three mouse events:
- mousedown - to start drawing the line
- mousemove - to continue drawing the line
- mouseup - to stop drawing the line
var board = document.getElementById(“board”);
board.addEventListener(“mousedown”,startPaintWithMouse,false);
board.addEventListener(“mousemove”,movePaintWithMouse,false);
board.addEventListener(“mouseup”,stopPaintWithMouseUp,false);
Here are the methods implementation:
Now, just add the buttons that change the line width and color and start to draw inside the html5 canvas element.
In the next post, We will learn how to record the user movements and to play it, just like the DrawSomething app.
var startPaintWithMouse = function(event) {
brushCtx = board.getContext(‘2d’); // get the context of the canvas
brushCtx.beginPath();
brushCtx.lineWidth = lineWidth; // set line width from variable
brushCtx.strokeStyle = color; // set line color from variable
brushCtx.moveTo(event.offsetX,event.offsetY); // start drawing from this point
};
var movePaintWithMouse = function(event) {
if (mouseState == 1) {
event.preventDefault();
brushCtx = board.getContext(‘2d’);
brushCtx.lineTo(event.offsetX,event.offsetY); // go to this point and draw
brushCtx.stroke(); // stroke the line
}
};
var stopPaintWithMouseUp = function(evet) {
mouseState = 0; // set mouse state to 0 to stop the draw
};
Now, just add the buttons that change the line width and color and start to draw inside the html5 canvas element.
In the next post, We will learn how to record the user movements and to play it, just like the DrawSomething app.
That is a good thing. I hope I could use it freely, nevertheless, its modifications are too complicated to me.
ReplyDeleteEach element is important in this structure of the code. We need to draw the clean lines to create the desired application.
ReplyDeleteBest top 10 digital marketing companies Tirupati
ReplyDeleteGreat Information, Thanks for sharing
Best igital marketing agencies in Anantapur
ReplyDeletehelpful information, thanks for writing and share this information
I would like to learn how to record the user movements and to play this game. It must be exciting!
ReplyDeleteVest Nice blog for learning new things,thanks for such beautiful blog.
ReplyDeletebelow some new idea plz check once.
kajal agarwal hot
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeletemicrosoft azure training in bangalore
rpa training in bangalore
rpa training in pune
best rpa training in bangalore
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
ReplyDeletepython Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
good post
ReplyDeletebrittanya razavi
thanks for sharing this information
ReplyDeletetableau training in bangalore
tableau training in bangalore btm
best tableau training institutes in bangalore
tableau classroom training in bangalore
python training in bangalore
best python training institute in bangalore
python training in jayanagar bangalore
python training in btm Layout
I’ve found extensive lists before, but none this informative. Thanks for sharing!
ReplyDeleteFor more details Click Here- SAP Training in Bangalore
Great! I like it. fiver logo online design
ReplyDeletenice blogsss....
ReplyDeletebrunei darussalam hosting
inplant training in chennai
Thanks For Sharing. Keep Posting
ReplyDeletebest React JS Training course in Bangalore
Blockchain training in Bangalore
python certification training in Bangalore
I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
ReplyDeleteData Science Course
It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.
ReplyDeleteData Science Training
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.Best data science courses in hyerabad
ReplyDeleteGreat information, nice to read your blog. Keep updating.
ReplyDeletepositive effects of social media
applications of artificial intelligence
ai applications
what is php used for in web design
rpa uipath jobs
php developer interview questions
Thanks for sharing information to our knowledge, it helps me plenty keep sharing…
ReplyDeleteTableau Training in Pune
Tableau Training Institutes in Pune
ReplyDeleteHello! I just wish to give an enormous thumbs up for the nice info you've got right here on this post. I will probably be coming back to your weblog for more soon!
data scientist training in hyderabad
ReplyDeleteI was basically inspecting through the web filtering for certain data and ran over your blog. I am flabbergasted by the data that you have on this blog. It shows how well you welcome this subject. Bookmarked this page, will return for extra. data science course in jaipur
Die Technologie entwickelt sich schneller denn je und schneller als Sie denken. Diese aufkommende Technologie wird unsere Lebensweise verändern.
ReplyDeleteThis post is so interactive and informative.keep update more information...
ReplyDeleteDigital Marketing Course in Tambaram
Digital Marketing Course in Chennai
I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog!
ReplyDeletebusiness analytics course in hyderabad
This post is very simple to read and appreciate without leaving any details out. Great work!
ReplyDeletebusiness analytics training in hyderabad
CBD products and oils are ideal for treating various conditions. Regardless, different people may not know how to use them to acquire the results. Accepting that you have endeavored CBD ahead of time and dropped by no outcome, read on to learn about the normal blunders you should maintain away from to exploit your product. CBD based products
ReplyDeleteSearch engines like fresh content and a blog site like Bcss8 is an excellent way to provide this. Blogs can be used to discuss your products or services and keep your readers up to date on industry trends. They can also be used to engage your customers and build strong relationships. Besides offering information, blogs can also show authority. A blog provides a more personal way to communicate with your audience and can be a good tool for improving your SEO. bcss8.com
Engaging with your readers through comments and discussions allows you to exchange ideas, gain new perspectives, and expand your knowledge base. The act of continuously learning and sharing knowledge through blogging can on an astoundingly key level impact personal growth and intellectual development. writeic
ReplyDeleteaydın
ReplyDeleteizmir
çankırı
giresun
konya
28BC
Obliging your news consumption to your preferences is at the heart of our platform. Re-attempt your news feed by selecting your areas of interest, and receive curated content that matters to you. We really need to ensure you're not overwhelmed by information yet rather empowered by it. theheralddiary
ReplyDeleteThe herald diary goes beyond text. We acknowledge the potency of visual storytelling, so we incorporate multimedia elements, for instance, high-definition images, captivating videos, interactive graphics, and podcasts into our articles. This multimedia strategy adds layers and reverberating to our reporting, making the news burst into life before your eyes.
ReplyDeleteAt the heart of the MagazineHerald lies a commitment to giving high-quality, stunning content that transcends the boundaries of traditional journalism. With a focus on totally reporting, engaging stories, and stunning visuals, each issue of the Magazine Herald is a journey into the realms of arts, culture, science, and lifestyle. magazineherald
ReplyDeleteThe Herald Daily continually offer customization features, allowing readers to tailor their news feed to their interests. This proposes that individuals can follow the topics and authors that matter most to them, ensuring a more personalized news experience. The internet has made the world smaller, and general news blog sites reflect this global perspective.
ReplyDeleteNews Credit has adapted to changing media consumption trends. Different idea multimedia content, including videos, podcasts, and infographics, catering to the preferences of a diverse audience. This adaptability ensures news blog websites stay relevant and engage in an ever-evolving digital landscape.
ReplyDelete