ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Canvas and Web Vector
                       Graphics
       Dylan Schiemann (@dylans)
       SitePen, Inc.
       HTML5 Code Camp, October, 2010


        ? SitePen, Inc. All Rights Reserved

Saturday, October 16, 2010
In the beginning, there was ASCII art
                   <img />
                   Microsoft and VML
                   Adobe, the W3C and SVG
                   Firefox and Opera get native SVG
                   Firefox, Opera and Safari get canvas
                   All non-IE browsers get canvas and SVG
                   IE9: 2011




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
1996




    Topology and Rheology of Quasi Two-Dimensional Foam
        http://arxiv.org/pdf/cond-mat/9904101


        ? SitePen, Inc. All Rights Reserved

Saturday, October 16, 2010
Raster vs. Vector

                   Raster: Rectangular grid of pixels
                          Pre-rendered before runtime (JPG, PNG)
                          Rendered at runtime (Canvas)
                   Vector: Mathematical representation of a shape
                          Rendered at runtime (SVG)




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Native vs. Plug-in

                   Open Protocols
                          No proprietary player or studio required
                   Use seamlessly with HTML, CSS, DOM
                   No install needed
                   A modular piece of the web rather than trying to replace it




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
SVG vs. Canvas
                                                                SVG                     Canvas
                      Representation                             Pixels                 DOM Nodes
                            Scalability                       Vector                       Raster
                           Syntax/Size                         Verbose                     Terse
                      Event Handling                     DOM Events                     Pixel Coords
                   Browser Support                    IE9 beta, all majors             IE9?, all majors
                     Mobile Support                              Many                      More
                          Animations                 JavaScript/SMIL                       Timers
                         Accessibility                            Yes                        No
                           Image Save                             No                 Yes (PNG or JPG)

        http://dev.opera.com/articles/view/svg-or-canvas-choosing-between-the-two/


        ? SitePen, Inc. All Rights Reserved

Saturday, October 16, 2010
2D vs. 3D

                   2D
                          SVG, Canvas, etc.
                   3D
                          WebGL (FF, Chrome, Safari dev builds)
                                replaces O3D, Canvas 3D
                          SVG 3D Transforms




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
CSS 3 Extensions

                   Bringing the most important parts of SVG to HTML+CSS!
                          Gradients
                          Transforms (2D and 3D)
                          Transitions
                          Animations
                          Masks
                   Blurring the lines
                          Canvas as a background image
                          HTML elements inside SVG elements




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Toolkits

                   Low-level (shapes, lines, events, etc.):
                          DojoX GFX (SVG, VML, Canvas, Silverlight, SVGWeb)
                          MooTools ART (SVG, VML)
                          Processing (Canvas)
                          Rapha?l (SVG, VML)
                   High-level
                          DojoX Charting, Drawing
                          MooTools ART Widgets
                          PlotKit and many other charting projects




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Toolkits

                   Low-level (shapes, lines, events, etc.):
                          Dojo GFX, MooTools ART, Processing, Rapha?l
                   High-level
                          DojoX Charting, Drawing
                          MooTools ART Widgets
                          PlotKit and many other charting projects




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Let's Draw Something




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Canvas Code - Basic Structure

          <!DOCTYPE html>
          <html lang="en">
          <head>
              <title>Canvas Example</title>
          </head>
          <body>

              <!-- canvas element; container -->
              <canvas id="myCanvas" width="320" height="320">
          Your browser does not have support for Canvas.
              </canvas>

          </body>
          </html>




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Canvas Example: London Ajax Logo

                <script>
                     // Set up a few variables, including our canvas and context
                     var canvas = document.getElementById('canvas'),
                         ctx = canvas.getContext('2d'),
                         grad;

                           // Build the path for the V
                           ctx.beginPath();
                           ctx.moveTo(7, 105);
                           ctx.lineTo(25, 105);
                           ctx.lineTo(60, 31);
                           ctx.lineTo(96, 105);
                           ctx.lineTo(114, 105);
                           ctx.lineTo(69, 11);
                           ctx.lineTo(52, 11);
                           ctx.closePath();

                           // Set up the stroke
                           ctx.strokeStyle = '#a70017';
                           ctx.stroke();

                           // Set up the gradient
                           grad = ctx.createLinearGradient(0, 0, 0, 105);
                           grad.addColorStop(0, '#f3001f');
                           grad.addColorStop(1, '#a40016');


    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Canvas Example: London Ajax Logo (cont)

                           // ... code continued from previous slide ...

                           // Apply the gradient to the V
                           ctx.fillStyle = grad;
                           ctx.fill();

                           // Create the blue box
                           ctx.fillStyle = '#0000ae';
                           ctx.fillRect(8, 68, 103, 16);

                      // Create the text
                      ctx.font = 'bold 9pt Arial';
                      ctx.fillStyle = '#ffffff';
                      ctx.fillText('LONDON AJAX', 16, 80);
                      ctx.strokeStyle = '#ffffff';
                      ctx.strokeText('LONDON AJAX', 16, 80);
                  </script>




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
SVG Code - Basic Structure

          <?xml version="1.0" standalone="no"?>
          <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/
          DTD/svg11.dtd">

          <!-- containing node -->
          <svg width=?"480" height=?"480">?

              <!-- defs: contains "referenced" elements -->
              <defs>?

              </defs>?

              <!-- add all shapes here -->

          </svg>




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010

I think of ¡°defs¡± as almost an array of vars, indexed by an ID attribute
SVG Example: London Ajax Logo

          <?xml version="1.0" standalone="no"?>
          <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/
          DTD/svg11.dtd">

          <!-- container -->
          <svg width="480" height="480" xmlns="http://www.w3.org/2000/svg" version="1.1">?

              <!-- definitions -->
              <defs>?

              <!-- linear gradient for the "A" -->
              <!-- referenced as "Gradient1" -->
              <linearGradient id="Gradient1" gradientUnits="userSpaceOnUse" x1="0.00000000"
          y1="0.00000000" x2="0.00000000" y2="420.00000000">?
                 <stop offset="0.00000000" stop-color="rgb(243, 0, 31)" stop-opacity="1">?</
          stop>?
                 <stop offset="1.00000000" stop-color="rgb(164, 0, 22)" stop-opacity="1">?</
          stop>?
              </linearGradient>?

              </defs>?

              <!-- shapes on next slide -->




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
SVG Example: London Ajax Logo (cont.)

              <!-- polyline to create the upside down "V" shape -->
              <!-- uses gradation fill -->
              <polyline fill="url(/slideshow/html5-codecampcanvasvectors/5460205/)" style="fill:url(/slideshow/html5-codecampcanvasvectors/5460205/);" stroke="rgb(167,
          0, 23)" stroke-opacity="1" stroke-width="1" stroke-linecap="butt" stroke-
          linejoin="miter" stroke-miterlimit="4" points="28 420 100 420 240 124 384 420 456
          420 276 44 208 44 28 420" stroke-dasharray="none" fill-rule="evenodd" />

              <!-- blue rect shape to complete the "A" -->
              <rect fill="rgb(0, 0, 174)" fill-opacity="1" stroke="none" stroke-opacity="0"
          stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-
          miterlimit="4" x="32" y="272" width="412" height="64" fill-rule="evenodd" />?

              <!-- text for "LONDON AJAX" -->
              <text fill="rgb(255, 255, 255)" fill-opacity="1" stroke="none" stroke-
          opacity="0" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-
          miterlimit="4" x="64" y="320" text-anchor="start" text-decoration="none" rotate="0"
          kerning="auto" text-rendering="optimizeLegibility" font-style="normal" font-
          variant="normal" font-weight="bold" font-size="36pt" font-family="Arial" fill-
          rule="evenodd">?LONDON AJAX?</text>?

          </svg>




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010

https://user.sitepen.com/~dwalsh/ajax-london.svg
Two Ways to Include SVG

                   <object>
                   <iframe>




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
GFX Example: London Ajax Logo

          <!-- node which will contain the drawing -->

          <script>
              // Require gfx
              dojo.require('dojox.gfx');
              dojo.require('dojox.gfx.gradient');

                  // When the resources have loaded....
                  dojo.ready(function() {

                           // Grab the DIV that will contain the drawing
                           var refNode = dojo.byId('someNode');

                           // Create the GFX "surface"
                           var surface = new dojox.gfx.createSurface(refNode,120,120);




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
GFX Example: London Ajax Logo (cont)

                  // Create an upside-down "V"
                  surface.createPolyline([
                      { x:7, y:105 },
                      { x:25, y:105 },
                      { x:60, y:31 },
                      { x:96, y:105 },
                      { x:114, y:105 },
                      { x:69, y:11 },
                      { x:52, y:11 },
                      { x:7, y:105 }
                  ]).
          setStroke({color:'#a70017'}).
          setFill({ type:'linear', x1:0, y1:0, x2:0, y2:105, colors: [{ offset:0,
          color:'#f3001f'},{ offset:1, color:'#a40016'}] });

                           // Create the blue box
                           surface.createRect({ x:8, y:68, width:103, height:16 }).
                                    setFill('#0000ae');

                           // Create the text
                           surface.createText({ x:16, y:80, text:'LONDON AJAX', align:'start'}).
                                    setFont({ family:'Arial', size:'9pt', weight:'bold' }).
                                    setFill('#ffffff');

              });
          </script>

    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Example

                   Fun with the London Ajax logo




    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
Canvas Compatibility

          <!DOCTYPE html>
          <html lang="en">
          <head>
              <title>Canvas Example</title>
          </head>
          <body>
           <canvas id="myCanvas" width="320" height="320">
             Your browser does not have support for Canvas.
           </canvas>
           <script>
                  var canvas = document.getElementById('myCanvas'),
                       ctx = canvas.getContext('2d'),
                       grad;
          " " ctx.fillRect(100, 25, 100, 50);

                  ctx.beginPath();
          " " // if you forget false in FF ff 3.6 or 4 beta, it won't draw?!?
                  ctx.arc(150, 150, 100, Math.PI * 3/2, Math.PI * 1/2, false);
                  ctx.lineWidth = 2;
                  ctx.lineCap = 'round';
                  ctx.strokeStyle = 'rgba(0, 127, 255, 0.3)';
                  ctx.stroke();
           </script>
          </body>
          </html>


    ? SitePen, Inc. All Rights Reserved
Saturday, October 16, 2010
? SitePen, Inc. All Rights Reserved

Saturday, October 16, 2010

More Related Content

Similar to Introduction to Canvas and Native Web Vector Graphics (20)

Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
dylanks
?
Svghtml5 Meetup
Svghtml5 MeetupSvghtml5 Meetup
Svghtml5 Meetup
Oswald Campesato
?
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
Lohith Goudagere Nagaraj
?
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
wendy017
?
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
?
HTML5 Intoduction for Web Developers
HTML5 Intoduction for Web DevelopersHTML5 Intoduction for Web Developers
HTML5 Intoduction for Web Developers
Sascha Corti
?
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Sadaaki HIRAI
?
HTML5 Intro
HTML5 IntroHTML5 Intro
HTML5 Intro
PavingWays Ltd.
?
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010
Patrick Lauke
?
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
?
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
soft-shake.ch
?
Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobileSvcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
Oswald Campesato
?
Bruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
Bruce Lawson, Web Development 2.0, SparkUp! Poznan PolandBruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
Bruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
brucelawson
?
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
Asher Martin
?
Word camp nextweb
Word camp nextwebWord camp nextweb
Word camp nextweb
Panagiotis Grigoropoulos
?
Word camp nextweb
Word camp nextwebWord camp nextweb
Word camp nextweb
GreekTuts ¦¥¦Ë¦Ë¦Ç¦Í¦É¦Ê? ¦¢¦Ï¦Ç¦È?¦Ì¦Á¦Ó¦Á
?
WordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWebWordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWeb
George Kanellopoulos
?
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
Helder da Rocha
?
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
Binary Studio
?
DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5
Cameron Kilgore
?
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
dylanks
?
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
wendy017
?
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
?
HTML5 Intoduction for Web Developers
HTML5 Intoduction for Web DevelopersHTML5 Intoduction for Web Developers
HTML5 Intoduction for Web Developers
Sascha Corti
?
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Familiar HTML5 - ÊÂÀý¤È¥µ¥ó¥×¥ë¥³©`¥É¤«¤éѧ¤Ö Éí½ü¤ÇÆÕͨ¤Ëʹ¤ï¤Æ¤¤¤ëHTML5
Sadaaki HIRAI
?
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010
Patrick Lauke
?
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
?
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
soft-shake.ch
?
Bruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
Bruce Lawson, Web Development 2.0, SparkUp! Poznan PolandBruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
Bruce Lawson, Web Development 2.0, SparkUp! Poznan Poland
brucelawson
?
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
Asher Martin
?
WordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWebWordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWeb
George Kanellopoulos
?
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
Helder da Rocha
?
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
Binary Studio
?
DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5
Cameron Kilgore
?

Recently uploaded (20)

Threat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community DayThreat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community Day
Teri Radichel
?
How to Achieve High-Accuracy Results When Using LLMs
How to Achieve High-Accuracy Results When Using LLMsHow to Achieve High-Accuracy Results When Using LLMs
How to Achieve High-Accuracy Results When Using LLMs
Aggregage
?
CEE Software Development M&A Report 2025
CEE Software Development M&A Report 2025CEE Software Development M&A Report 2025
CEE Software Development M&A Report 2025
Yevgen Sysoyev
?
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
?
UiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified AppsUiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified Apps
UiPathCommunity
?
Build With AI X GDG Harare Beginners .pdf
Build With AI X GDG Harare Beginners .pdfBuild With AI X GDG Harare Beginners .pdf
Build With AI X GDG Harare Beginners .pdf
Google Developer Group - Harare
?
Innovative Web Design | Malachite Technologies
Innovative Web Design | Malachite TechnologiesInnovative Web Design | Malachite Technologies
Innovative Web Design | Malachite Technologies
malachitetechnologie1
?
Introduction to Mobile App Development.
Introduction to  Mobile App Development.Introduction to  Mobile App Development.
Introduction to Mobile App Development.
AkashDwivedi43
?
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB plc
?
Presentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdfPresentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdf
Mukesh Kala
?
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdfBrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
Nick Samuel
?
APAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdfAPAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdf
GDG on Campus Monash
?
Codequiry: A Code Similarity Checker Every Developer Should Know
Codequiry: A Code Similarity Checker Every Developer Should KnowCodequiry: A Code Similarity Checker Every Developer Should Know
Codequiry: A Code Similarity Checker Every Developer Should Know
Code Quiry
?
Artificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examplesArtificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examples
anandsimple
?
TNBC Research Presentation and medical virology .pptx
TNBC Research Presentation and medical virology .pptxTNBC Research Presentation and medical virology .pptx
TNBC Research Presentation and medical virology .pptx
MohamedHasan816582
?
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Agile ME
?
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
DianaGray10
?
Top 10 Mobile Hacking Tools ¨C 2025 Edition
Top 10 Mobile Hacking Tools ¨C 2025 EditionTop 10 Mobile Hacking Tools ¨C 2025 Edition
Top 10 Mobile Hacking Tools ¨C 2025 Edition
anishachhikara2122
?
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
Ivan Tang
?
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Buwaneka De Silva
?
Threat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community DayThreat Modeling a Batch Job System - AWS Security Community Day
Threat Modeling a Batch Job System - AWS Security Community Day
Teri Radichel
?
How to Achieve High-Accuracy Results When Using LLMs
How to Achieve High-Accuracy Results When Using LLMsHow to Achieve High-Accuracy Results When Using LLMs
How to Achieve High-Accuracy Results When Using LLMs
Aggregage
?
CEE Software Development M&A Report 2025
CEE Software Development M&A Report 2025CEE Software Development M&A Report 2025
CEE Software Development M&A Report 2025
Yevgen Sysoyev
?
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
?
UiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified AppsUiPath Community Dubai: Discover Unified Apps
UiPath Community Dubai: Discover Unified Apps
UiPathCommunity
?
Innovative Web Design | Malachite Technologies
Innovative Web Design | Malachite TechnologiesInnovative Web Design | Malachite Technologies
Innovative Web Design | Malachite Technologies
malachitetechnologie1
?
Introduction to Mobile App Development.
Introduction to  Mobile App Development.Introduction to  Mobile App Development.
Introduction to Mobile App Development.
AkashDwivedi43
?
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB Berlin Roadshow ºÝºÝߣs - 8 April 2025
MariaDB plc
?
Presentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdfPresentation Session 4 -Agent Builder.pdf
Presentation Session 4 -Agent Builder.pdf
Mukesh Kala
?
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdfBrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
BrightonSEO April 2025 - hreflang XML E-Commerce - Nick Samuel.pdf
Nick Samuel
?
APAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdfAPAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdf
GDG on Campus Monash
?
Codequiry: A Code Similarity Checker Every Developer Should Know
Codequiry: A Code Similarity Checker Every Developer Should KnowCodequiry: A Code Similarity Checker Every Developer Should Know
Codequiry: A Code Similarity Checker Every Developer Should Know
Code Quiry
?
Artificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examplesArtificial Neural Networks, basics, its variations and examples
Artificial Neural Networks, basics, its variations and examples
anandsimple
?
TNBC Research Presentation and medical virology .pptx
TNBC Research Presentation and medical virology .pptxTNBC Research Presentation and medical virology .pptx
TNBC Research Presentation and medical virology .pptx
MohamedHasan816582
?
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Leadership in the AI Era: The Reinvention of Human-Centered Leadership by Bor...
Agile ME
?
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
SAP Automation with UiPath: Leveraging AI for SAP Automation - Part 8 of 8
DianaGray10
?
Top 10 Mobile Hacking Tools ¨C 2025 Edition
Top 10 Mobile Hacking Tools ¨C 2025 EditionTop 10 Mobile Hacking Tools ¨C 2025 Edition
Top 10 Mobile Hacking Tools ¨C 2025 Edition
anishachhikara2122
?
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
2025-04-05 - Block71 Event - The Landscape of GenAI and Ecosystem.pdf
Ivan Tang
?
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Atlassian Community - Human-Centered AI in Product Management Unleashing Inno...
Buwaneka De Silva
?

Introduction to Canvas and Native Web Vector Graphics

  • 1. Canvas and Web Vector Graphics Dylan Schiemann (@dylans) SitePen, Inc. HTML5 Code Camp, October, 2010 ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 2. In the beginning, there was ASCII art <img /> Microsoft and VML Adobe, the W3C and SVG Firefox and Opera get native SVG Firefox, Opera and Safari get canvas All non-IE browsers get canvas and SVG IE9: 2011 ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 3. 1996 Topology and Rheology of Quasi Two-Dimensional Foam http://arxiv.org/pdf/cond-mat/9904101 ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 4. Raster vs. Vector Raster: Rectangular grid of pixels Pre-rendered before runtime (JPG, PNG) Rendered at runtime (Canvas) Vector: Mathematical representation of a shape Rendered at runtime (SVG) ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 5. Native vs. Plug-in Open Protocols No proprietary player or studio required Use seamlessly with HTML, CSS, DOM No install needed A modular piece of the web rather than trying to replace it ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 6. SVG vs. Canvas SVG Canvas Representation Pixels DOM Nodes Scalability Vector Raster Syntax/Size Verbose Terse Event Handling DOM Events Pixel Coords Browser Support IE9 beta, all majors IE9?, all majors Mobile Support Many More Animations JavaScript/SMIL Timers Accessibility Yes No Image Save No Yes (PNG or JPG) http://dev.opera.com/articles/view/svg-or-canvas-choosing-between-the-two/ ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 7. 2D vs. 3D 2D SVG, Canvas, etc. 3D WebGL (FF, Chrome, Safari dev builds) replaces O3D, Canvas 3D SVG 3D Transforms ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 8. CSS 3 Extensions Bringing the most important parts of SVG to HTML+CSS! Gradients Transforms (2D and 3D) Transitions Animations Masks Blurring the lines Canvas as a background image HTML elements inside SVG elements ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 9. Toolkits Low-level (shapes, lines, events, etc.): DojoX GFX (SVG, VML, Canvas, Silverlight, SVGWeb) MooTools ART (SVG, VML) Processing (Canvas) Rapha?l (SVG, VML) High-level DojoX Charting, Drawing MooTools ART Widgets PlotKit and many other charting projects ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 10. Toolkits Low-level (shapes, lines, events, etc.): Dojo GFX, MooTools ART, Processing, Rapha?l High-level DojoX Charting, Drawing MooTools ART Widgets PlotKit and many other charting projects ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 11. Let's Draw Something ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 12. Canvas Code - Basic Structure <!DOCTYPE html> <html lang="en"> <head> <title>Canvas Example</title> </head> <body> <!-- canvas element; container --> <canvas id="myCanvas" width="320" height="320"> Your browser does not have support for Canvas. </canvas> </body> </html> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 13. Canvas Example: London Ajax Logo <script> // Set up a few variables, including our canvas and context var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), grad; // Build the path for the V ctx.beginPath(); ctx.moveTo(7, 105); ctx.lineTo(25, 105); ctx.lineTo(60, 31); ctx.lineTo(96, 105); ctx.lineTo(114, 105); ctx.lineTo(69, 11); ctx.lineTo(52, 11); ctx.closePath(); // Set up the stroke ctx.strokeStyle = '#a70017'; ctx.stroke(); // Set up the gradient grad = ctx.createLinearGradient(0, 0, 0, 105); grad.addColorStop(0, '#f3001f'); grad.addColorStop(1, '#a40016'); ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 14. Canvas Example: London Ajax Logo (cont) // ... code continued from previous slide ... // Apply the gradient to the V ctx.fillStyle = grad; ctx.fill(); // Create the blue box ctx.fillStyle = '#0000ae'; ctx.fillRect(8, 68, 103, 16); // Create the text ctx.font = 'bold 9pt Arial'; ctx.fillStyle = '#ffffff'; ctx.fillText('LONDON AJAX', 16, 80); ctx.strokeStyle = '#ffffff'; ctx.strokeText('LONDON AJAX', 16, 80); </script> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 15. SVG Code - Basic Structure <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/ DTD/svg11.dtd"> <!-- containing node --> <svg width=?"480" height=?"480">? <!-- defs: contains "referenced" elements --> <defs>? </defs>? <!-- add all shapes here --> </svg> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010 I think of ¡°defs¡± as almost an array of vars, indexed by an ID attribute
  • 16. SVG Example: London Ajax Logo <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/ DTD/svg11.dtd"> <!-- container --> <svg width="480" height="480" xmlns="http://www.w3.org/2000/svg" version="1.1">? <!-- definitions --> <defs>? <!-- linear gradient for the "A" --> <!-- referenced as "Gradient1" --> <linearGradient id="Gradient1" gradientUnits="userSpaceOnUse" x1="0.00000000" y1="0.00000000" x2="0.00000000" y2="420.00000000">? <stop offset="0.00000000" stop-color="rgb(243, 0, 31)" stop-opacity="1">?</ stop>? <stop offset="1.00000000" stop-color="rgb(164, 0, 22)" stop-opacity="1">?</ stop>? </linearGradient>? </defs>? <!-- shapes on next slide --> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 17. SVG Example: London Ajax Logo (cont.) <!-- polyline to create the upside down "V" shape --> <!-- uses gradation fill --> <polyline fill="url(/slideshow/html5-codecampcanvasvectors/5460205/)" style="fill:url(/slideshow/html5-codecampcanvasvectors/5460205/);" stroke="rgb(167, 0, 23)" stroke-opacity="1" stroke-width="1" stroke-linecap="butt" stroke- linejoin="miter" stroke-miterlimit="4" points="28 420 100 420 240 124 384 420 456 420 276 44 208 44 28 420" stroke-dasharray="none" fill-rule="evenodd" /> <!-- blue rect shape to complete the "A" --> <rect fill="rgb(0, 0, 174)" fill-opacity="1" stroke="none" stroke-opacity="0" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke- miterlimit="4" x="32" y="272" width="412" height="64" fill-rule="evenodd" />? <!-- text for "LONDON AJAX" --> <text fill="rgb(255, 255, 255)" fill-opacity="1" stroke="none" stroke- opacity="0" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke- miterlimit="4" x="64" y="320" text-anchor="start" text-decoration="none" rotate="0" kerning="auto" text-rendering="optimizeLegibility" font-style="normal" font- variant="normal" font-weight="bold" font-size="36pt" font-family="Arial" fill- rule="evenodd">?LONDON AJAX?</text>? </svg> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010 https://user.sitepen.com/~dwalsh/ajax-london.svg
  • 18. Two Ways to Include SVG <object> <iframe> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 19. GFX Example: London Ajax Logo <!-- node which will contain the drawing --> <script> // Require gfx dojo.require('dojox.gfx'); dojo.require('dojox.gfx.gradient'); // When the resources have loaded.... dojo.ready(function() { // Grab the DIV that will contain the drawing var refNode = dojo.byId('someNode'); // Create the GFX "surface" var surface = new dojox.gfx.createSurface(refNode,120,120); ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 20. GFX Example: London Ajax Logo (cont) // Create an upside-down "V" surface.createPolyline([ { x:7, y:105 }, { x:25, y:105 }, { x:60, y:31 }, { x:96, y:105 }, { x:114, y:105 }, { x:69, y:11 }, { x:52, y:11 }, { x:7, y:105 } ]). setStroke({color:'#a70017'}). setFill({ type:'linear', x1:0, y1:0, x2:0, y2:105, colors: [{ offset:0, color:'#f3001f'},{ offset:1, color:'#a40016'}] }); // Create the blue box surface.createRect({ x:8, y:68, width:103, height:16 }). setFill('#0000ae'); // Create the text surface.createText({ x:16, y:80, text:'LONDON AJAX', align:'start'}). setFont({ family:'Arial', size:'9pt', weight:'bold' }). setFill('#ffffff'); }); </script> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 21. Example Fun with the London Ajax logo ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 22. Canvas Compatibility <!DOCTYPE html> <html lang="en"> <head> <title>Canvas Example</title> </head> <body> <canvas id="myCanvas" width="320" height="320"> Your browser does not have support for Canvas. </canvas> <script> var canvas = document.getElementById('myCanvas'), ctx = canvas.getContext('2d'), grad; " " ctx.fillRect(100, 25, 100, 50); ctx.beginPath(); " " // if you forget false in FF ff 3.6 or 4 beta, it won't draw?!? ctx.arc(150, 150, 100, Math.PI * 3/2, Math.PI * 1/2, false); ctx.lineWidth = 2; ctx.lineCap = 'round'; ctx.strokeStyle = 'rgba(0, 127, 255, 0.3)'; ctx.stroke(); </script> </body> </html> ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010
  • 23. ? SitePen, Inc. All Rights Reserved Saturday, October 16, 2010