Canvas Shapes Using images

One of the more exciting features of <canvas> is the ability to use images. These can be used to do dynamic photo compositing or as backdrops of graphs, for sprites in games, and so forth. External images can be used in any format supported by the browser, such as PNG, GIF, or JPEG. You can even use the image produced by other canvas elements on the same page as the source!
Importing images into a canvas is basically a two step process:
  1. Get a reference to an HTMLImageElement object or to another canvas element as a source. It isn't possible to use images by simply providing a URL or path to them.
  2. Draw the image on the canvas using the drawImage() function.
Let's take a look at how to do this.

Getting images to draw

Drawing shapes with canvas

The grid

Before we can start drawing, we need to talk about the canvas grid or coordinate space. The HTML template on the previous page had a canvas element 150 pixels wide and 150 pixels high. To the right, you see this canvas with the default grid overlayed. Normally 1 unit in the grid corresponds to 1 pixel on the canvas. The origin of this grid is positioned in the top left corner (coordinate (0,0)). All elements are placed relative to this origin. So the position of the top left corner of the blue square becomes x pixels from the left and y pixels from the top (coordinate (x,y)). Later in this tutorial we'll see how we can translate the origin to a different position, rotate the grid and even scale it. For now we'll stick to the default.

Drawing rectangles

Unlike SVG, <canvas> only supports one primitive shape: rectangles. All other shapes must be created by combining one or more paths. Luckily, we have an assortment of path drawing functions which make it possible to compose very complex shapes.

Basic usage of Canvas

The <canvas> element

Let's start this tutorial by looking at the <canvas> element itself.
<canvas id="tutorial" width="150" height="150"></canvas>
This looks a lot like the <img> element, the only difference is that it doesn't have the src and alt attributes. The <canvas> element has only two attributes - width and height. These are both optional and can also be set using DOM properties. When no width and height attributes are specified, the canvas will initially be 300 pixels wide and 150 pixels high. The element can be sized arbitrarily by CSS, but during rendering the image is scaled to fit its layout size.
Note: If your renderings seem distorted, try specifying your width and height attributes explicitly in the <canvas> attributes, and not using CSS.
The id attribute isn't specific to the <canvas> element but is one of the default HTML attributes which can be applied to (almost) every HTML element (likeclass for instance). It's always a good idea to supply an id because this makes it much easier to identify it in our script.

How to use HTML5′s drag and drop

Drag and drop is a part of the HTML5 standard.

Drag and Drop

Drag and drop is a very common feature. It is when you "grab" an object and drag it to a different location.

In HTML5, drag and drop is part of the standard, and any element can be draggable.

Browser Support

Blogger Getting Started Guide

Blogger Getting Started Guide

This guide can walk you through how to create a blog, and help you familiarize yourself with the main features of Blogger.

To start using Blogger, simply sign in with your Google Account. (If you use Gmail, Google Groups, or orkut, you already have an account.) If you don't have a Google Account yet, you can create one now.

Contents

  • Create a blog
  • Dashboard
  • Overview
  • Write a post
  • Add an image
  • Add a video
  • Customize
  • Privacy and permissions

Convert Menu to Dropdown



HTML5 Introduction

What Is HTML5?


HTML5 is the newest hyper text markup language for websites from the World Wide Web Consortium (W3C). The first draft was made public in 2008, but not much happened until 2011. In 2011, HTML5 was released and people started writing about it and using it, but the support in different browsers was still poor. Today all major browsers (Chrome, Safari, Firefox, Opera, IE) offer HTML5 support, therefore the newest HTML technology can be used at its best today.

How to Hide the WordPress Upgrade Message in the Dashboard


When you have built your site on an open source project like WordPress one of the benefits you get is continuous updates and improvements to the core code.

WordPress aims to release a couple of versions per year, when there is a new version of WordPress available to download there will be a notification bar at the top of your admin area. This notification bar will let you know that your WordPress version is out of date and that you need to update the core code.

Powered by Blogger.