14
DINA GOLDSHTEIN HTML5 Canvas

HTML5 Canvas

  • Upload
    dinazil

  • View
    227

  • Download
    7

Embed Size (px)

DESCRIPTION

HTML5 has a bunch of cool features, which are now mostly supported by all major browsers on desktops and mobile devices. We will briefly introduce some of these features and explain how they fit into the HTML/CSS/JavaScript ecosystem. Then, we will talk about the HTML5 Canvas API, which can be used to draw shapes inside standard web pages and apply transformations and zooms.

Citation preview

Page 1: HTML5 Canvas

DINA GOLDSHTEIN

HTML5 Canvas

Page 2: HTML5 Canvas

Agenda

HTML5 IntroductionCanvas MotivationCanvas BasicsOne Big Demo

Page 3: HTML5 Canvas

Why HTML5?

Internet has changed a lot since 1996SpaceJam vs. Google Docs

HTML5 is the latest HTML standardDelivers rich content without the need for

external pluginsReplaces some scripting with more markupAll major browsers support it (to some extent*)

* http://html5test.com/

Page 4: HTML5 Canvas

What’s New in HTML5?

<canvas> element for 2D drawing<video> and <audio> for media playbackLocal storage supportGeolocation APIWeb Workers for background calculationsSemantic elements like <article>, <footer>, <header>, <aside>

Tons of input controls: color, email, date, time

And much more…

Page 5: HTML5 Canvas

What Can Canvas do for You?

Well, pretty much anything…

Cloth ExperimentAngry BirdsShared Canvas

Lots of other (less cool) examples

Page 6: HTML5 Canvas

Canvas Basic

The Canvas element allows you to draw 2D graphics, on the fly, on a Web page, using JavaScript

The HTML5 canvas is a lot like a real-world painting canvas You can use different colors and different brushes You can rotate it or move it around Anything you paint on it stays in place until you delete

it You can resize it

But it’s also a bit different, duh

Page 7: HTML5 Canvas

Hello Canvas

DEMO

Page 8: HTML5 Canvas

Canvas Basic Recipe

Get Canvas elementGet drawing context from elementRepeat:

Save context properties Set new properties: fill style, stroke style, transform Begin path Define path Close path (if needed) Fill and/or stroke Restore original properties

Page 9: HTML5 Canvas

What is a Path?

A path is a series of points connected by lines Use beginPath to initialize a path Use lineTo, arcTo, etc. to connect lines Stroke and/or fill as see fit

A path can be closed Use closePath to connect last point to first point

A path doesn’t have to be continuous Use moveTo to create discontinuous sections in a path

Page 10: HTML5 Canvas

Paths

DEMO

Page 11: HTML5 Canvas

Canvas Features

Styling•fillStyle•strokeStyle•lineCap•lineWidth

Shapes•rect•fillRect•srokeRect•clearRect•arc

Paths•fill•stroke•beginPath•closePath•moveTo

Lines•lineTo•quadraticCurveTo•bezierCurveTo•arcTo

Text•font•fillText•strokeText•measureText

Images•drawImage

Page 12: HTML5 Canvas

Transformations

DEMO

Page 13: HTML5 Canvas

Grand Finale - PaintJS

DEMO

Page 14: HTML5 Canvas

Questions?