SlideShare a Scribd company logo
HTML5 Graphics
Dave Isbitski
Sr. Developer Evangelist
David.Isbitski@microsoft.com
blogs.msdn.com/davedev
@TheDaveDev
HTML5 and Friends




                                                 via Giorgio Sardo:
     blogs.msdn.com/b/giorgio/archive/2010/10/28/what-is-html5.aspx
HTML



CSS     JavaScript
Cascading Style Sheets (CSS)

CSS 2.1
   Support Widespread

Many New CSS3 Modules
   Backgrounds & Borders
   Color
   Fonts (including WOFF)
   Media Queries
   Namespaces
   Selectors
   Values & Units
   Box Shadow
   2D & 3D Transforms, Transitions
The Power of the Whole PC

     GREETINGS PROFESSOR FALKEN.

      WOULD YOU LIKE TO PLAY A
           GAME OF CHESS?

                 █
IE9 Hardware Acceleration
  A Tale of GPUs and CPUs

GPUs Commonplace
  Text, Video, and Graphics


Multiple Processor Cores
(WEI Mar 2011 = 2.42)

Support for both in
Internet Explorer 9 (and beyond)
Scalable Vector Graphics (SVG)

SVG 1.1
Vector Based
  Use Geometry
XML format
  Familiarity
  Readability
  Accessibility
SVG Graphics
Declarative, XML based, royalty-free format for
describing 2D Vector graphics
Broad Adoption and Tools – released September
4, 2001
Shapes:
  ‘path’, ‘rect’, ‘circle’, ‘ellipse’,
  ‘line’, ‘polyline’ and ‘polygon’
Text
Solid Colors, Linear and Radial Gradients,
Patterns
Styling (inline & CSS)
Retained v. Immediate

Retained mode retains a complete model of
the objects to be rendered
  Example: SVG
Immediate mode directly causes rendering of
graphics objects to the display
  Example: HTML5 Canvas
SVG 101
<svg width="400" height="200"
xmlns="http://www.w3.org/2000/svg">
    <rect fill="red" x="20" y="20" width="100" height="75" />
    <rect fill="blue" x="50" y="50" width="100" height="75" />
</svg>
Advantages of SVG
Static or Dynamic
Preserves Fidelity
  Vectors, High-DPI, Printing, etc.
Declarative syntax (i.e. tooling)
Improved accessibility
  Part of the DOM, Screen Readers
Interactivity through events
Supports embedded content (ie. XML
fragments)
SVG

 Demos
Some SVG Generation Tools
Inkscape
  http://inkscape.org

Adobe Illustrator
  Export to SVG
  BTW: AI -> Canvas
     http://visitmix.com/labs/ai2canvas

Microsoft Visio
  Save as SVG
  http://office.microsoft.com/visio
Some SVG Libraries
 RaphaelJS
   http://raphaeljs.com


 Dojo Toolkit
   http://dojotoolkit.org


 Protovis
   Graphing library
   http://vis.stanford.edu/protovis
HTML5 Canvas
Dynamic, scriptable
rendering of 2D
shapes and bitmaps
Simple API; 45
methods and 21
attributes
Typically hardware-
accelerated
HTML5 Canvas
HTML5 Element
                              U haz an old
  Bitmap Based                  browser
  JavaScript Driven

2D API
  Rectangles, Paths, Lines,
  Fills, Arcs, Curves, etc.

“Immediate Mode”
Colours and
  State       Compositing
                              Styles


                              Simple
Line Styles    Shadows
                              Shapes


 Complex        Focus
                               Text
 Shapes       Management


                       Pixel
          Images
                    Manipulation
Canvas on One Canvas!
state                             Shadows                             text
                                          attribute double                   attribute DOMString font;
    void save();
                                          shadowOffsetX;                     attribute DOMString textAlign;
    void restore();
                                          attribute double                   attribute DOMString textBaseline;
transformations                                                              void fillText(…);
                                          shadowOffsetY;
    void   scale(…);                                                         void strokeText(…);
    void   rotate(…);
                                          attribute double
                                          shadowBlur;                        TextMetrics measureText(…);
    void   translate(…);                                              pixel manipulation
                                          attribute DOMString
    void   transform(…);                                                     ImageData createImageData(…);
                                          shadowColor;
    void   setTransform(…);                                                  ImageData createImageData(…);
                                  Rects
compositing                                                                  ImageData getImageData(…);
                                          void clearRect(…);
    globalAlpha;                                                             void putImageData(…);
                                          void fillRect(…);
    globalCompositeOperation;
                                          void strokeRect(…);         interface CanvasGradient {
colors and styles
                                  path API                                   void addColorStop(…); };
    strokeStyle;
                                          void beginPath();           interface CanvasPattern {};
    fillStyle;
    CanvasGradient                        void closePath();           interface TextMetrics {
    createLinearGradient(…);              void moveTo(…);                    readonly attribute double width;
    CanvasGradient                        void lineTo(…);                    };
    createRadialGradient(…);              void quadraticCurveTo(…);   interface ImageData {
    CanvasPattern                                                            readonly attribute unsigned long
                                          void bezierCurveTo(…);             width;
    createPattern(…);
                                          void arcTo(…);                     readonly attribute unsigned long
Line caps/joins                           void rect(…);                      height;
    attribute double lineWidth;                                              readonly attribute
                                          void arc(…);
    attribute DOMString                                                      CanvasPixelArray data; };
    lineCap;                              void fill();
                                                                      interface CanvasPixelArray {
    attribute DOMString                   void stroke();
                                                                             readonly attribute unsigned long
    lineJoin;                             void clip();                       length;
    attribute double                      boolean isPointInPath(…);          getter octet (…);
    miterLimit;
                                  focus management                           setter void (…); };
                                          boolean drawFocusRing(…);
                                  drawing images
                                          void drawImage(…);
                                                                      Via Jatinder Mann – MIX11
Canvas 101
<canvas id="myCanvas" width="200" height="200">
  No canvas support.
</canvas>

<script type="text/javascript">
  var canvas = document.getElementById("myCanvas");
  var ctx = canvas.getContext("2d");
  ctx.fillStyle = "rgb(255,0,0)";
  ctx.fillRect(30, 30, 50, 50);
</script>
Some Advantages of HTML5 Canvas
 Script-based scene graph
 Programmatic generation of
 images
 Drawing pixels
 Constant performance
HTML5 Canvas

  Demos
Best Practice: Feature Detection
var canvas =
document.createElement(“canvas”);
   if (canvas && canvas.getContext &&
       canvas.getContext(“2d”))
   {
        // Code requiring canvas support
   } else {
        // Canvas isn’t available.
        // Put non-canvas fallback here
   }
A Canvas Library Example

  EaselJS
    http://easeljs.com
svg versus canvas
SVG and Canvas

              Canvas                         SVG

Abstraction   Pixel based                    Shape based

Elements      Single HTML element            Multiple graphical elements
                                             which become part of the DOM

Driver        Script only                    Script and CSS

Event Model   User Interaction is granular   User Interaction is abstracted
              (x,y)                          (rect, path)

Performance   Performance is better with    Performance is better with
              smaller surface and/or larger smaller number of objects
              number of objects             and/or larger surface.

                                                       Via Jatinder Mann - MIX
Scenarios: Canvas and SVG

                    Complex
                 scenes, lots of
Screen Capture       objects
                                                       Static Images
                                     Interactive       (logos, diagrams,
                                   Charts, Graphs            etc.)




                                                       High Fidelity
                                    2D Gaming         Documents for
                                                         Viewing,
                                                         Printing
  Video                    Web
Manipulation            Advertising
                                                    Or… consider both!
Resources
Demos and More
  BeautyOfTheWeb.com
  IETestDrive.com
  msdn.com/ie

SVG & Canvas
  http://msdn.com/gg193983.aspx

Sessions
  live.visitmix.com, buildwindows.com
HTML5 Graphics
Dave Isbitski
Sr. Developer Evangelist
David.Isbitski@microsoft.com
blogs.msdn.com/davedev
@TheDaveDev

More Related Content

PDF
MS TechDays 2011 - HTML 5 All the Awesome Bits
PDF
SVGo: a Go Library for SVG generation
PDF
Qt quickatlinuxcollaborationsummit2010
PPT
CodeMash - Building Rich Apps with Groovy SwingBuilder
PPTX
Code Contracts In .Net
PDF
HTML5 Canvas - The Future of Graphics on the Web
PDF
7 Habits For a More Functional Swift
PPTX
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)
MS TechDays 2011 - HTML 5 All the Awesome Bits
SVGo: a Go Library for SVG generation
Qt quickatlinuxcollaborationsummit2010
CodeMash - Building Rich Apps with Groovy SwingBuilder
Code Contracts In .Net
HTML5 Canvas - The Future of Graphics on the Web
7 Habits For a More Functional Swift
HTML5 - Chances and Pitfalls (Bytro Labs GmbH)

Similar to HTML5 Graphics - Canvas and SVG (20)

PDF
Intro to HTML5 Canvas
PDF
How to build a html5 websites.v1
PDF
Writing a Space Shooter with HTML5 Canvas
KEY
An in-depth look at jQuery
KEY
Processing presentation
PDF
Google I/O 2013 - Android Graphics Performance
PDF
Google I/O 2013 - Android Graphics Performance
PDF
Unconventional webapps with gwt:elemental & html5
PPTX
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
PPT
Html5 Canvas Drawing and Animation
PDF
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
PDF
Mlocjs buzdin
PDF
Skia & Freetype - Android 2D Graphics Essentials
PPTX
Bringing your app to the web with Dart - Chris Buckett (Entity Group)
PPTX
How to make a video game
PPTX
introduction of HTML canvas and styles .pptx
PDF
Overcoming The Impedance Mismatch Between Source Code And Architecture
PPTX
SVGD3Angular2React
PDF
Google's HTML5 Work: what's next?
PDF
Visualization of Big Data in Web Apps
Intro to HTML5 Canvas
How to build a html5 websites.v1
Writing a Space Shooter with HTML5 Canvas
An in-depth look at jQuery
Processing presentation
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
Unconventional webapps with gwt:elemental & html5
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
Html5 Canvas Drawing and Animation
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Mlocjs buzdin
Skia & Freetype - Android 2D Graphics Essentials
Bringing your app to the web with Dart - Chris Buckett (Entity Group)
How to make a video game
introduction of HTML canvas and styles .pptx
Overcoming The Impedance Mismatch Between Source Code And Architecture
SVGD3Angular2React
Google's HTML5 Work: what's next?
Visualization of Big Data in Web Apps
Ad

More from David Isbitski (16)

PDF
Screencast dave dev-introtoask-andecho-july2015
PPTX
Lap Around Azure Build Updates
PPTX
Hosting a WordPress Blog on Azure Websites
PPTX
Azure Mobile Services for iOS
PPTX
Building Apps for the new Windows Store
PPTX
Windows Phone 8 Sensors
PPTX
More Than An App
PPTX
Designing for Windows Phone 8
PPTX
A Developer Lap Around Windows Phone 8
PPTX
Windows Azure Mobile Services
PPTX
Windows Store Apps with HTML and JavaScript
PPTX
Designing a Windows Store App
PPTX
Playing music and sound effects in a windows 8 metro style app using html5 an...
PPTX
Windows Phone App Development
PPTX
HTML5 Gaming
PPTX
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
Screencast dave dev-introtoask-andecho-july2015
Lap Around Azure Build Updates
Hosting a WordPress Blog on Azure Websites
Azure Mobile Services for iOS
Building Apps for the new Windows Store
Windows Phone 8 Sensors
More Than An App
Designing for Windows Phone 8
A Developer Lap Around Windows Phone 8
Windows Azure Mobile Services
Windows Store Apps with HTML and JavaScript
Designing a Windows Store App
Playing music and sound effects in a windows 8 metro style app using html5 an...
Windows Phone App Development
HTML5 Gaming
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
Ad

Recently uploaded (20)

PPTX
Machine Learning_overview_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Machine Learning_overview_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
Per capita expenditure prediction using model stacking based on satellite ima...

HTML5 Graphics - Canvas and SVG

  • 1. HTML5 Graphics Dave Isbitski Sr. Developer Evangelist David.Isbitski@microsoft.com blogs.msdn.com/davedev @TheDaveDev
  • 2. HTML5 and Friends via Giorgio Sardo: blogs.msdn.com/b/giorgio/archive/2010/10/28/what-is-html5.aspx
  • 3. HTML CSS JavaScript
  • 4. Cascading Style Sheets (CSS) CSS 2.1 Support Widespread Many New CSS3 Modules Backgrounds & Borders Color Fonts (including WOFF) Media Queries Namespaces Selectors Values & Units Box Shadow 2D & 3D Transforms, Transitions
  • 5. The Power of the Whole PC GREETINGS PROFESSOR FALKEN. WOULD YOU LIKE TO PLAY A GAME OF CHESS? █
  • 6. IE9 Hardware Acceleration A Tale of GPUs and CPUs GPUs Commonplace Text, Video, and Graphics Multiple Processor Cores (WEI Mar 2011 = 2.42) Support for both in Internet Explorer 9 (and beyond)
  • 7. Scalable Vector Graphics (SVG) SVG 1.1 Vector Based Use Geometry XML format Familiarity Readability Accessibility
  • 8. SVG Graphics Declarative, XML based, royalty-free format for describing 2D Vector graphics Broad Adoption and Tools – released September 4, 2001 Shapes: ‘path’, ‘rect’, ‘circle’, ‘ellipse’, ‘line’, ‘polyline’ and ‘polygon’ Text Solid Colors, Linear and Radial Gradients, Patterns Styling (inline & CSS)
  • 9. Retained v. Immediate Retained mode retains a complete model of the objects to be rendered Example: SVG Immediate mode directly causes rendering of graphics objects to the display Example: HTML5 Canvas
  • 10. SVG 101 <svg width="400" height="200" xmlns="http://www.w3.org/2000/svg"> <rect fill="red" x="20" y="20" width="100" height="75" /> <rect fill="blue" x="50" y="50" width="100" height="75" /> </svg>
  • 11. Advantages of SVG Static or Dynamic Preserves Fidelity Vectors, High-DPI, Printing, etc. Declarative syntax (i.e. tooling) Improved accessibility Part of the DOM, Screen Readers Interactivity through events Supports embedded content (ie. XML fragments)
  • 13. Some SVG Generation Tools Inkscape http://inkscape.org Adobe Illustrator Export to SVG BTW: AI -> Canvas http://visitmix.com/labs/ai2canvas Microsoft Visio Save as SVG http://office.microsoft.com/visio
  • 14. Some SVG Libraries RaphaelJS http://raphaeljs.com Dojo Toolkit http://dojotoolkit.org Protovis Graphing library http://vis.stanford.edu/protovis
  • 15. HTML5 Canvas Dynamic, scriptable rendering of 2D shapes and bitmaps Simple API; 45 methods and 21 attributes Typically hardware- accelerated
  • 16. HTML5 Canvas HTML5 Element U haz an old Bitmap Based browser JavaScript Driven 2D API Rectangles, Paths, Lines, Fills, Arcs, Curves, etc. “Immediate Mode”
  • 17. Colours and State Compositing Styles Simple Line Styles Shadows Shapes Complex Focus Text Shapes Management Pixel Images Manipulation
  • 18. Canvas on One Canvas! state Shadows text attribute double attribute DOMString font; void save(); shadowOffsetX; attribute DOMString textAlign; void restore(); attribute double attribute DOMString textBaseline; transformations void fillText(…); shadowOffsetY; void scale(…); void strokeText(…); void rotate(…); attribute double shadowBlur; TextMetrics measureText(…); void translate(…); pixel manipulation attribute DOMString void transform(…); ImageData createImageData(…); shadowColor; void setTransform(…); ImageData createImageData(…); Rects compositing ImageData getImageData(…); void clearRect(…); globalAlpha; void putImageData(…); void fillRect(…); globalCompositeOperation; void strokeRect(…); interface CanvasGradient { colors and styles path API void addColorStop(…); }; strokeStyle; void beginPath(); interface CanvasPattern {}; fillStyle; CanvasGradient void closePath(); interface TextMetrics { createLinearGradient(…); void moveTo(…); readonly attribute double width; CanvasGradient void lineTo(…); }; createRadialGradient(…); void quadraticCurveTo(…); interface ImageData { CanvasPattern readonly attribute unsigned long void bezierCurveTo(…); width; createPattern(…); void arcTo(…); readonly attribute unsigned long Line caps/joins void rect(…); height; attribute double lineWidth; readonly attribute void arc(…); attribute DOMString CanvasPixelArray data; }; lineCap; void fill(); interface CanvasPixelArray { attribute DOMString void stroke(); readonly attribute unsigned long lineJoin; void clip(); length; attribute double boolean isPointInPath(…); getter octet (…); miterLimit; focus management setter void (…); }; boolean drawFocusRing(…); drawing images void drawImage(…); Via Jatinder Mann – MIX11
  • 19. Canvas 101 <canvas id="myCanvas" width="200" height="200"> No canvas support. </canvas> <script type="text/javascript"> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "rgb(255,0,0)"; ctx.fillRect(30, 30, 50, 50); </script>
  • 20. Some Advantages of HTML5 Canvas Script-based scene graph Programmatic generation of images Drawing pixels Constant performance
  • 21. HTML5 Canvas Demos
  • 22. Best Practice: Feature Detection var canvas = document.createElement(“canvas”); if (canvas && canvas.getContext && canvas.getContext(“2d”)) { // Code requiring canvas support } else { // Canvas isn’t available. // Put non-canvas fallback here }
  • 23. A Canvas Library Example EaselJS http://easeljs.com
  • 25. SVG and Canvas Canvas SVG Abstraction Pixel based Shape based Elements Single HTML element Multiple graphical elements which become part of the DOM Driver Script only Script and CSS Event Model User Interaction is granular User Interaction is abstracted (x,y) (rect, path) Performance Performance is better with Performance is better with smaller surface and/or larger smaller number of objects number of objects and/or larger surface. Via Jatinder Mann - MIX
  • 26. Scenarios: Canvas and SVG Complex scenes, lots of Screen Capture objects Static Images Interactive (logos, diagrams, Charts, Graphs etc.) High Fidelity 2D Gaming Documents for Viewing, Printing Video Web Manipulation Advertising Or… consider both!
  • 27. Resources Demos and More BeautyOfTheWeb.com IETestDrive.com msdn.com/ie SVG & Canvas http://msdn.com/gg193983.aspx Sessions live.visitmix.com, buildwindows.com
  • 28. HTML5 Graphics Dave Isbitski Sr. Developer Evangelist David.Isbitski@microsoft.com blogs.msdn.com/davedev @TheDaveDev

Editor's Notes

  • #11: Z order is whichever is first so red rect is before blue-rect can be inline in html or external resources.
  • #13: Election Results – High Fidelity: http://ie.microsoft.com/testdrive/Graphics/AtlaszurEuropawahl/Default.xhtml – Zoom in and out. LOB applications, and dynamic.
  • #16: 2004 – Apple in Webkit. Used to power dashboard widgets and safari browser itself.2006 – general use by folks Now part of HTML5APIs is part of low level drawing API – Immediate mode is very fast performance.
  • #18: Can incorporate video and even get rgb value of a pixel.
  • #22: http://ie.microsoft.com/testdrive/Graphics/CanvasPad/Default.htmlRectangles, arcs and then quadratic. Show clipping and talk about interval timer. Then show gradient calls on kite and show shadows. Them image and video (could even do transforms on rgb values of video). Show transforms and animation. ctx.shadowColor = &apos;red&apos;; other timer gradual fades what was visible into background via 0.1.