background preloader

Html5/JavaScript

Facebook Twitter

Sketching with HTML5 Canvas and “Brush Images” In a previous post on capturing user signatures in mobile applications, I explored how you capture user input from mouse or touch events and visualize that in a HTML5 Canvas.

Sketching with HTML5 Canvas and “Brush Images”

Inspired by activities with my daughter, I decided to take this signature capture component and make it a bit more fun & exciting. My daughter and I often draw and sketch together… whether its a magnetic sketching toy, doodling on the iPad, or using a crayon and a placemat at a local pizza joint, there is always something to draw. (Note: I never said I was actually good at drawing.) You can take that exact same signature capture example, make the canvas bigger, and then combine it with a tablet and a stylus, and you’ve got a decent sketching application. However, after doodling a bit you will quickly notice that your sketches leave something to be desired. If you switch your approach away from moveTo and lineTo, then things can get interesting with a minimal amount of changes.

Now, let’s examine how it all works. Ant512 / CanvasLayers. Www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf. Download. A Gentle Introduction to Making HTML5 Canvas Interactive. I wrote a book on HTML5, including three chapters on Canvas!

A Gentle Introduction to Making HTML5 Canvas Interactive

Buy it here. This is a big overhaul of one of my tutorials on making and moving shapes on an HTML5 Canvas. This new tutorial is vastly cleaner than my old one, but if you still want to see that one or are looking for the concept of a “ghost context” you can find that one here. This tutorial will show you how to create a simple data structure for shapes on an HTML5 canvas and how to have them be selectable. The finished canvas will look like this: Click to drag the shapes. We’ll be going over a few things that are essential to interactive apps such as games (drawing loop, hit testing), and in later tutorials I will probably turn this example into a small game of some kind. HTML5 Canvas Image Data Tutorial. HTML5 Canvas Drawing Lines with Smooth Edges. In the previous post we kicked off with our painting application using HTML5 canvas.

HTML5 Canvas Drawing Lines with Smooth Edges

If you remember well, we ended up with a basic app where one can easily draw lines or something else with a “pencil” tool. But there was a problem. When drawing different shapes like circles, the lines/curves had jagged edges. They were not smooth or anti-aliased, whatever you want to call them. This article will aim towards solving those issues. The Simple Way – Using moveTo() more If we save the mouse.x and mouse.y in a temporary variable and use that to “move to” everytime onmousemove (inside onPaint function) – then that can improve the result substantially. This is how you would store the “last” mouse positions: onPaint() will also need some changes: Quite straightforward. Problems Take a look at the demo first (drag to sketch): Although improvements in the edges can be noticed, it is still not entirely smooth.

The More Accurate Way – Using quadraticCurveTo() Thanks to this SO answer that helped out. Demo. Creating an HTML5 canvas painting application. By Mihai Sucan Table of contents Introduction My previous HTML5 canvas tutorial provided you with insight into the numerous use cases for canvas in web applications.

Creating an HTML5 canvas painting application

In this article we will explore how you can write your own canvas-based painting application. Making a web application that allows users to draw on a canvas requires several important steps: setting up your HTML document with a canvas context (a canvas element with an id), setting up your script to target that canvas context and draw inside it and adding the required mouse event handlers for user interaction and associated logic. The final painting application example looks like this: To make it easier to follow along with the code walkthrough presented below, you can download the full code example and follow along with it as you read the article. Getting started with the HTML.

Html5 - How to save a canvas drawing. Improving HTML5 Canvas Performance. Introduction HTML5 canvas, which started as an experiment from Apple, is the most widely supported standard for 2D immediate mode graphics on the web.

Improving HTML5 Canvas Performance

Many developers now rely on it for a wide variety of multimedia projects, visualizations, and games. However, as the applications we build increase in complexity, developers inadvertently hit the performance wall. Saving Canvas Data as an Image. Over the past few months, we have talked quite a bit about HTML5, more specifically canvases.

Saving Canvas Data as an Image

There are plenty of other interesting HTML5 subjects canvases offer, which makes it by far the most fascinating and flexible object. We have covered topics ranging from simple rotations to photo filters. Today we are going to go over how to take your canvas and save it as an image. Introduction Getting the pixel data from a canvas is fairly simple, as we learned in the grayscale filter tutorial. Before we get started with some code, it should be noted that you can only get image data, in any form, from sources on the same domain on the canvas. As a result, due to the constraints of having javascript on the page on Tech.Pro Tutorials (only fiddles allowed), we do not have a demo, however all of the code needed to get started is below: HTML Example Digging In Now, the code to get your image data is actually really straight forward. Once you have this string, you can use it many different ways.