SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
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(#Gradient1)" style="fill:url(#Gradient1);" 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

Contenu connexe

Similaire à Introduction to Canvas and Native Web Vector Graphics

Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
wendy017
 
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
 
WordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWebWordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWeb
George Kanellopoulos
 
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
 

Similaire à Introduction to Canvas and Native Web Vector Graphics (20)

Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Svghtml5 Meetup
Svghtml5 MeetupSvghtml5 Meetup
Svghtml5 Meetup
 
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
 
Basic html5 and javascript
Basic html5 and javascriptBasic html5 and javascript
Basic html5 and javascript
 
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?
 
HTML5 Intoduction for Web Developers
HTML5 Intoduction for Web DevelopersHTML5 Intoduction for Web Developers
HTML5 Intoduction for Web Developers
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 
HTML5 Intro
HTML5 IntroHTML5 Intro
HTML5 Intro
 
Speak the Web 15.02.2010
Speak the Web 15.02.2010Speak the Web 15.02.2010
Speak the Web 15.02.2010
 
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
 
soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5soft-shake.ch - Introduction to HTML5
soft-shake.ch - Introduction to HTML5
 
Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobileSvcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
 
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
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 
Word camp nextweb
Word camp nextwebWord camp nextweb
Word camp nextweb
 
Word camp nextweb
Word camp nextwebWord camp nextweb
Word camp nextweb
 
WordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWebWordCamp Thessaloniki2011 The NextWeb
WordCamp Thessaloniki2011 The NextWeb
 
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
 
Academy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphicsAcademy PRO: HTML5 API graphics
Academy PRO: HTML5 API graphics
 
DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5DevChatt: The Wonderful World Of Html5
DevChatt: The Wonderful World Of Html5
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 

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(#Gradient1)" style="fill:url(#Gradient1);" 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