SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
Canvas
         Ivano Malavolta
    ivano.malavolta@univaq.it
http://www.di.univaq.it/malavolta
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Canvas

    Canvas allows you to draw anything inside the browser




http://bit.ly/LC8AgY
http://bit.ly/LULa79
http://bit.ly/LUKXkr
http://bit.ly/Ie4HKu
Canvas
    It uses nothing more than JavaScript and HTML
         no external plugins, no libraries, etc.

    You can create lines, use images, use text, apply
      transformations, etc.




http://bit.ly/KsKLv1
Canvas


      A canvas is a rectangular
     area, where you can control
     every pixel using JavaScript



           Returns a string
       representing an encoded
      URL containing the grabbed
            graphical data
Coordinate System

    Canvas uses the standard screen coordinate system




http://bit.ly/KsNip6
toDataUrl()




              image/png
Context


It is the built-in Javascript object
   for the canvas HTML element                     2D or WebGL
                                                available contexts



                                       It has methods to draw lines,
                                          boxes, circles, and more


                    push state on state stack
                        pop state from the stack and restore it
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Colors & Style




           we can style any shape
             within the canvas
Colors & Style




        the distance between the inner
     corner and the outer corner in a line
Colors & Style
                           you can use this objects as a value
                              to strokeStyle or fillStyle




                                         creates a pattern
                                           from an image

                                              [repeat |
                                             repeat-x |
                                              repeat-y
Specifies the gradient's
                                            | no-repeat]
  position and color
Gradient Example
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Drawing Rectangles




                             All pixels inside this area
                                   will be erased

                                  Creates a filled
                                     rectangle


Creates an empty rectangle
Drawing Complex Shapes
    A complex shape is represented by a Path where a
                                        Path,
      path is a list of subpaths

    Subpaths are one or more points connected by straight
      or curved lines




    The rendering context has always a current path

http://bit.ly/KsSc5q
Paths
                                     Starts a new path, or
                                    clears the current path


                                     Creates a line from the
                                      last point to the first
                                               point


                                     Fills the current path
                                     with the selected color
Creates an area in the
canvas, and this area is
                                   Draws the path on the
the only visible area in
                                          canvas
      the canvas
Paths (continued)             Moves the path to the
                               specified point (x,y),
                              without creating a line



                               Creates a line from the
                              last point in the path to
                                 the given point (x,y)


                            Creates a quadratic curve
                            from the current point in
 Creates a Bezier curve     the path to the specified
from the current point in          point (x,y)
the path to the specified
       point (x,y)
Paths (continued)
                                        Creates an arc
                                      between two points



                                           draws along a circle




checks if the given point is
                               creates a
        in the path
                               rectangle
Examples
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Images
          draw the image, and
         specify the width and
                 height




         clip the image, draw it,
          and specify the width
                and height
Pixels
                                               Creates an empty
                                             imagedata object with
                                              the given dimensions

                                                  Creates a new
                                                imagedata object,
                                               containing data from
                                                    the canvas




    Draws imagedata onto the canvas
(optionally, you can specify which part of
     the imageData you want to put)
Pixels
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
scale the canvas, based on
         width and height          Transformations
    (also positioning is scaled)
                                    rotate the canvas, based on
                                       the angle (in radians)

                                    move the canvas horizontally
                                           and vertically




   this is not
relative to past
  transforms
A word on radians

A Radian is the ratio between the length of an arc and
  its radius




    x degrees = x * PI/180
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Text    draws text on the
                                   canvas, and fills it
                                  with the color set by
                                      the fillStyle
                                        attribute

                                   draws text on the
                                     canvas, without
                                    filling, using the
                                       color of the
                                      strokeStyle
                                       attribute

measures the given text string
(returns the result in pixels)
Text
                            sets the font
                        (same syntax of CSS)




                         align text on the
                              canvas




vertical alignment of
       the text
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Compositing

   transparency
  of the drawings




  how drawings are
 positioned onto the
        canvas
Roadmap

•   Intro
•   Colors & Style
•   Drawings
•   Images & Pixels
•   Transformations
•   Text
•   Compositing
•   Animations
Animations




               determines the
             optimal FPS for our
                  animation
References




http://www.w3schools.com/html5/html5_ref_canvas.asp
http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf

Mais conteúdo relacionado

Mais procurados

Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effectsナム-Nam Nguyễn
 
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATION
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATIONCOLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATION
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATIONecij
 
Digital Image Fundamentals
Digital Image FundamentalsDigital Image Fundamentals
Digital Image FundamentalsKalyan Acharjya
 
الوسائط المتعددة Multimedia تاج
الوسائط المتعددة  Multimedia تاجالوسائط المتعددة  Multimedia تاج
الوسائط المتعددة Multimedia تاجmaaz hamed
 

Mais procurados (6)

Multimedia searching
Multimedia searchingMultimedia searching
Multimedia searching
 
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special EffectsImproved Alpha-Tested Magnification for Vector Textures and Special Effects
Improved Alpha-Tested Magnification for Vector Textures and Special Effects
 
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATION
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATIONCOLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATION
COLOUR IMAGE ENHANCEMENT BASED ON HISTOGRAM EQUALIZATION
 
Digital Image Fundamentals
Digital Image FundamentalsDigital Image Fundamentals
Digital Image Fundamentals
 
MMT image & graphics
MMT image & graphicsMMT image & graphics
MMT image & graphics
 
الوسائط المتعددة Multimedia تاج
الوسائط المتعددة  Multimedia تاجالوسائط المتعددة  Multimedia تاج
الوسائط المتعددة Multimedia تاج
 

Semelhante a HTML5 Canvas

Javascript Canvas API
Javascript Canvas APIJavascript Canvas API
Javascript Canvas APISamuel Santos
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationMindfire Solutions
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebRobin Hawkes
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Vector And Illustrator 03
Vector And Illustrator 03Vector And Illustrator 03
Vector And Illustrator 03PaperStainer
 
Fundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFatihahIrra
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 

Semelhante a HTML5 Canvas (20)

Javascript Canvas API
Javascript Canvas APIJavascript Canvas API
Javascript Canvas API
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
 
HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Vector And Illustrator 03
Vector And Illustrator 03Vector And Illustrator 03
Vector And Illustrator 03
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 
Fundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdf
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Textile designing
Textile designingTextile designing
Textile designing
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Homework
HomeworkHomework
Homework
 
R graphics
R graphicsR graphics
R graphics
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Scmad Chapter06
Scmad Chapter06Scmad Chapter06
Scmad Chapter06
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 

Mais de Ivano Malavolta

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Ivano Malavolta
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)Ivano Malavolta
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green ITIvano Malavolta
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Ivano Malavolta
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]Ivano Malavolta
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Ivano Malavolta
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Ivano Malavolta
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Ivano Malavolta
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Ivano Malavolta
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Ivano Malavolta
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Ivano Malavolta
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Ivano Malavolta
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Ivano Malavolta
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile developmentIvano Malavolta
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architecturesIvano Malavolta
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design LanguageIvano Malavolta
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languagesIvano Malavolta
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software ArchitectureIvano Malavolta
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineeringIvano Malavolta
 

Mais de Ivano Malavolta (20)

Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
 
The H2020 experience
The H2020 experienceThe H2020 experience
The H2020 experience
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)The Green Lab - Research cocktail  @Vrije Universiteit Amsterdam (October 2020)
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
 
Software sustainability and Green IT
Software sustainability and Green ITSoftware sustainability and Green IT
Software sustainability and Green IT
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]How Maintainability Issues of Android Apps Evolve [ICSME 2018]
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...Collaborative Model-Driven Software Engineering: a Classification Framework a...
Collaborative Model-Driven Software Engineering: a Classification Framework a...
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...Modeling behaviour via UML state machines [Software Design] [Computer Science...
Modeling behaviour via UML state machines [Software Design] [Computer Science...
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
 
Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...Modeling and abstraction, software development process [Software Design] [Com...
Modeling and abstraction, software development process [Software Design] [Com...
 
[2017/2018] Agile development
[2017/2018] Agile development[2017/2018] Agile development
[2017/2018] Agile development
 
Reconstructing microservice-based architectures
Reconstructing microservice-based architecturesReconstructing microservice-based architectures
Reconstructing microservice-based architectures
 
[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language[2017/2018] AADL - Architecture Analysis and Design Language
[2017/2018] AADL - Architecture Analysis and Design Language
 
[2017/2018] Architectural languages
[2017/2018] Architectural languages[2017/2018] Architectural languages
[2017/2018] Architectural languages
 
[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture[2017/2018] Introduction to Software Architecture
[2017/2018] Introduction to Software Architecture
 
[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering[2017/2018] RESEARCH in software engineering
[2017/2018] RESEARCH in software engineering
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

HTML5 Canvas

  • 1. Canvas Ivano Malavolta ivano.malavolta@univaq.it http://www.di.univaq.it/malavolta
  • 2. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 3. Canvas Canvas allows you to draw anything inside the browser http://bit.ly/LC8AgY http://bit.ly/LULa79 http://bit.ly/LUKXkr http://bit.ly/Ie4HKu
  • 4. Canvas It uses nothing more than JavaScript and HTML no external plugins, no libraries, etc. You can create lines, use images, use text, apply transformations, etc. http://bit.ly/KsKLv1
  • 5. Canvas A canvas is a rectangular area, where you can control every pixel using JavaScript Returns a string representing an encoded URL containing the grabbed graphical data
  • 6. Coordinate System Canvas uses the standard screen coordinate system http://bit.ly/KsNip6
  • 7. toDataUrl() image/png
  • 8. Context It is the built-in Javascript object for the canvas HTML element 2D or WebGL available contexts It has methods to draw lines, boxes, circles, and more push state on state stack pop state from the stack and restore it
  • 9. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 10. Colors & Style we can style any shape within the canvas
  • 11. Colors & Style the distance between the inner corner and the outer corner in a line
  • 12. Colors & Style you can use this objects as a value to strokeStyle or fillStyle creates a pattern from an image [repeat | repeat-x | repeat-y Specifies the gradient's | no-repeat] position and color
  • 14. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 15. Drawing Rectangles All pixels inside this area will be erased Creates a filled rectangle Creates an empty rectangle
  • 16. Drawing Complex Shapes A complex shape is represented by a Path where a Path, path is a list of subpaths Subpaths are one or more points connected by straight or curved lines The rendering context has always a current path http://bit.ly/KsSc5q
  • 17. Paths Starts a new path, or clears the current path Creates a line from the last point to the first point Fills the current path with the selected color Creates an area in the canvas, and this area is Draws the path on the the only visible area in canvas the canvas
  • 18. Paths (continued) Moves the path to the specified point (x,y), without creating a line Creates a line from the last point in the path to the given point (x,y) Creates a quadratic curve from the current point in Creates a Bezier curve the path to the specified from the current point in point (x,y) the path to the specified point (x,y)
  • 19. Paths (continued) Creates an arc between two points draws along a circle checks if the given point is creates a in the path rectangle
  • 21. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 22. Images draw the image, and specify the width and height clip the image, draw it, and specify the width and height
  • 23. Pixels Creates an empty imagedata object with the given dimensions Creates a new imagedata object, containing data from the canvas Draws imagedata onto the canvas (optionally, you can specify which part of the imageData you want to put)
  • 25. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 26. scale the canvas, based on width and height Transformations (also positioning is scaled) rotate the canvas, based on the angle (in radians) move the canvas horizontally and vertically this is not relative to past transforms
  • 27. A word on radians A Radian is the ratio between the length of an arc and its radius x degrees = x * PI/180
  • 28. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 29. Text draws text on the canvas, and fills it with the color set by the fillStyle attribute draws text on the canvas, without filling, using the color of the strokeStyle attribute measures the given text string (returns the result in pixels)
  • 30. Text sets the font (same syntax of CSS) align text on the canvas vertical alignment of the text
  • 31. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 32. Compositing transparency of the drawings how drawings are positioned onto the canvas
  • 33. Roadmap • Intro • Colors & Style • Drawings • Images & Pixels • Transformations • Text • Compositing • Animations
  • 34. Animations determines the optimal FPS for our animation