SlideShare una empresa de Scribd logo
1 de 42
Canvas5 Drawing and Animation 
HTML 
Presenter: Ashim Das, Mindfire Solutions 
Skype: mfsi_ashim 
Date: 13/11/2013
Reference
The Canvas Element
Use document.getElementById() to get a 
reference to canvas 
Call getContext('2d') on the canvas to get the 
graphics context 
Use the context to draw in the canvas
The Canvas API 
Canvas attributes 
width 
height 
Canvas methods 
getContext() 
toDataURL(type, quality) 
toBlob(callback, type, args...)
The Canvas Context 
Although the context provides 2d graphics context, the 
Canvas specification embraces other types of contexts as 
well; for example, a 3d context specification is already 
well underway. 
CanvasRenderingContext2D attributes 
canvas miterLimit 
fillStyle shadowBlur 
font shadowColor 
globalAlpha shadowOffsetX 
globalComposite-Operation shadowOffsetY 
lineCap strokeStyle 
lineWidth textAlign 
lineJoin textBaseline
Event Handling 
Mouse Events 
canvas.onmousedown = function(e) { 
//mouse down event reaction 
}; 
or 
canvas.addEventListener('mousedown', function(e) { 
//mouse down event reaction 
});
Event Handling 
Keyboard Events 
Key Events 
keydown 
keypress 
keyup 
var key = String.fromCharCode(event.which); 
Touch Events 
touchstart 
touchmove 
touchend 
touchcancel 
canvas.ontouchstart = function(e) {….....
Invisible HTML Elements 
Rubber band with a floating div 
Printing a canvas 
Using toDataURL() to print a canvas
Drawing
The Coordinate System
Transformation 
Translate 
Rotate 
Scale 
Create custom transformations, such as shear
The Drawing Model 
Draws the shape or image into an infinite, transparent bitmap, 
honoring the current fill, stroke, and line styles. 
Draws the shadow from the shape or image into a second bitmap, 
using the current context shadow settings. 
Multiplies every shadow pixel's alpha component by the 
globalAlpha property of the context. 
Composites the shadow bitmap into the canvas clipped to the 
clipping region, using the current composition. 
Multiplies every pixel for the shape or image by the globalAlpha 
property of the context. 
Composites the shape or image bitmap into the clipping region 
over the current canvas bitmap, using the current composition 
operator.
Drawing Rectangles 
clearRect(double x, double y, double w, double h) 
strokeRect(double x, double y, double w, double h) 
fillRect(double x, double y, double w, double h) 
Colors and Transparency
Gradients 
Linear Gradients 
createLinearGradient( 
double x0, double y0, 
double x1, double y1) 
Radial Gradients 
createRadialGradient( 
double x0, double y0, 
double r0, double x1, 
double y1, double r1)
Patterns 
createPattern(HTMLImageElement | HTMLCanvasElement | 
HTMLVideoElement image, DOMString repetition)
Shadows 
shadowColor: a CSS3 color 
shadowOffsetX: the horizontal offset in pixels from shape 
or text to the shadow 
shadowOffsetY: the vertical offset in pixels from shape or 
text to the shadow 
shadowBlur: a value, used in a Gaussian blur equation to 
smear the shadow 
Inset Shadows 
Negative values in OffSet
Paths, Stroking, and Filling
Cutouts
Lines 
moveTo(x, y) 
lineTo(x, y) 
Drawing a Grid
Rubberband Lines 
Dashed Lines
Line Caps and Joins
Arcs and Circles 
arc(x, y, radius, startAngle, endAngle, counterClockwise) 
Rubberband Circles 
Rounded Rectangles (the arcTo() 
method)
Dials and Gauges
Bezier Curves 
quadraticCurveTo(double 
cpx, double cpy, double x, 
double y) 
Rounded corners with bezier 
curves
Cubic Curves 
bezierCurveTo(double cpx, double cpy, double cp2x, double 
cp2y, double x, double y)
Transformations 
rotate(double angleInRadians) 
scale(double x, double y) 
translate(double x, double y) 
Custom Transformations 
transform(double a, double b, double c, double d, double e, 
double f) 
setTransform(double a, double b, double c, double d, double e, 
double f)
Text
Methods 
rotate(double angleInRadians) 
scale(double x, double y) 
translate(double x, double y) 
Properties 
font 
textAlign 
textBaseline
Stroking and Filling Text
Text Patterns and Gradients
Setting Font Properties 
font-style 
font-variant 
font-weight 
font-size 
line-height 
font-family
Positioning Text 
textAlign 
textBaseline
Text around arcs
Text cursors
Animation
The requestAnimationFrame() 
method 
function animate(time) { 
// Update and draw animation objects 
requestAnimationFrame(animate); // Sustain the animation 
} ... 
requestAnimationFrame(animate); // Start the animation 
long window.requestAnimationFrame(FrameRequestCallback 
callback) 
void window.cancelRequestAnimationFrame(long handle)
Portable Animation loop 
The requestAnimationFrame() polyfill
Scrolling Backgrounds
Parallax
Timed Animation
Thank 
You

Más contenido relacionado

La actualidad más candente

Tools & Resources for Data Visualisation
Tools & Resources for Data VisualisationTools & Resources for Data Visualisation
Tools & Resources for Data VisualisationAmit Kapoor
 
Visualising Big Data
Visualising Big DataVisualising Big Data
Visualising Big DataAmit Kapoor
 
Animation Institute in Pune
Animation Institute in PuneAnimation Institute in Pune
Animation Institute in PuneClassboat.com
 
rlottie - a new approach to motion graphics ui
rlottie -  a new approach to motion graphics uirlottie -  a new approach to motion graphics ui
rlottie - a new approach to motion graphics uiHermet Park
 
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 Q
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 QNational Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 Q
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 QQAAET_BH
 
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 Q
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 QNational Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 Q
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 QQAAET_BH
 

La actualidad más candente (8)

L1 slides
L1 slidesL1 slides
L1 slides
 
Tools & Resources for Data Visualisation
Tools & Resources for Data VisualisationTools & Resources for Data Visualisation
Tools & Resources for Data Visualisation
 
Visualising Big Data
Visualising Big DataVisualising Big Data
Visualising Big Data
 
Animation Institute in Pune
Animation Institute in PuneAnimation Institute in Pune
Animation Institute in Pune
 
rlottie - a new approach to motion graphics ui
rlottie -  a new approach to motion graphics uirlottie -  a new approach to motion graphics ui
rlottie - a new approach to motion graphics ui
 
Ar1 twf030 lecture2.2
Ar1 twf030 lecture2.2Ar1 twf030 lecture2.2
Ar1 twf030 lecture2.2
 
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 Q
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 QNational Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 Q
National Examinations 2010, QAAET, Bahrain, maths, grade 9, paper 1 Q
 
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 Q
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 QNational Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 Q
National Examinations 2010, Bahrain, QAAET, maths, grade 9, paper 2 Q
 

Destacado

ベジェ曲線を書いてみた
ベジェ曲線を書いてみたベジェ曲線を書いてみた
ベジェ曲線を書いてみたHiromu Shioya
 
Basic Concepts of Animation
Basic Concepts of AnimationBasic Concepts of Animation
Basic Concepts of Animationjamalharun
 
12 Concepts of Animation
12 Concepts of Animation12 Concepts of Animation
12 Concepts of Animationjaspang
 
Animation techniques for CG students
Animation techniques for CG studentsAnimation techniques for CG students
Animation techniques for CG studentsMahith
 
Animation Techniques
Animation TechniquesAnimation Techniques
Animation TechniquesMedia Studies
 
(Computer) Animation Technique
(Computer) Animation Technique(Computer) Animation Technique
(Computer) Animation Techniquejustinesolano
 
Introduction to Animation
Introduction to AnimationIntroduction to Animation
Introduction to Animationmrnasim
 
Computer Animation PowerPoint
Computer Animation PowerPointComputer Animation PowerPoint
Computer Animation PowerPointoacore2
 

Destacado (12)

ベジェ曲線を書いてみた
ベジェ曲線を書いてみたベジェ曲線を書いてみた
ベジェ曲線を書いてみた
 
Dhtml sohaib ch
Dhtml sohaib chDhtml sohaib ch
Dhtml sohaib ch
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
Basic Concepts of Animation
Basic Concepts of AnimationBasic Concepts of Animation
Basic Concepts of Animation
 
12 Concepts of Animation
12 Concepts of Animation12 Concepts of Animation
12 Concepts of Animation
 
Animation techniques for CG students
Animation techniques for CG studentsAnimation techniques for CG students
Animation techniques for CG students
 
Animation Techniques
Animation TechniquesAnimation Techniques
Animation Techniques
 
(Computer) Animation Technique
(Computer) Animation Technique(Computer) Animation Technique
(Computer) Animation Technique
 
Introduction to Animation
Introduction to AnimationIntroduction to Animation
Introduction to Animation
 
Animation
AnimationAnimation
Animation
 
ANIMATION PPT
ANIMATION PPTANIMATION PPT
ANIMATION PPT
 
Computer Animation PowerPoint
Computer Animation PowerPointComputer Animation PowerPoint
Computer Animation PowerPoint
 

Similar a 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 WebRobin Hawkes
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationAnthony Starks
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphicsRafi_Dar
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphicsAmol Gaikwad
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Takao Wada
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...Susang Kim
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bPhilip Schwarz
 
An Introduction to NV_path_rendering
An Introduction to NV_path_renderingAn Introduction to NV_path_rendering
An Introduction to NV_path_renderingMark Kilgard
 

Similar a Html5 Canvas Drawing and Animation (20)

Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
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
 
SVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generationSVGo: a Go Library for SVG generation
SVGo: a Go Library for SVG generation
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
Unit-1 basics of computer graphics
Unit-1 basics of computer graphicsUnit-1 basics of computer graphics
Unit-1 basics of computer graphics
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
An Introduction to NV_path_rendering
An Introduction to NV_path_renderingAn Introduction to NV_path_rendering
An Introduction to NV_path_rendering
 

Más de Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Último

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 

Último (20)

A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 

Html5 Canvas Drawing and Animation

  • 1. Canvas5 Drawing and Animation HTML Presenter: Ashim Das, Mindfire Solutions Skype: mfsi_ashim Date: 13/11/2013
  • 4. Use document.getElementById() to get a reference to canvas Call getContext('2d') on the canvas to get the graphics context Use the context to draw in the canvas
  • 5. The Canvas API Canvas attributes width height Canvas methods getContext() toDataURL(type, quality) toBlob(callback, type, args...)
  • 6. The Canvas Context Although the context provides 2d graphics context, the Canvas specification embraces other types of contexts as well; for example, a 3d context specification is already well underway. CanvasRenderingContext2D attributes canvas miterLimit fillStyle shadowBlur font shadowColor globalAlpha shadowOffsetX globalComposite-Operation shadowOffsetY lineCap strokeStyle lineWidth textAlign lineJoin textBaseline
  • 7. Event Handling Mouse Events canvas.onmousedown = function(e) { //mouse down event reaction }; or canvas.addEventListener('mousedown', function(e) { //mouse down event reaction });
  • 8. Event Handling Keyboard Events Key Events keydown keypress keyup var key = String.fromCharCode(event.which); Touch Events touchstart touchmove touchend touchcancel canvas.ontouchstart = function(e) {….....
  • 9. Invisible HTML Elements Rubber band with a floating div Printing a canvas Using toDataURL() to print a canvas
  • 12. Transformation Translate Rotate Scale Create custom transformations, such as shear
  • 13. The Drawing Model Draws the shape or image into an infinite, transparent bitmap, honoring the current fill, stroke, and line styles. Draws the shadow from the shape or image into a second bitmap, using the current context shadow settings. Multiplies every shadow pixel's alpha component by the globalAlpha property of the context. Composites the shadow bitmap into the canvas clipped to the clipping region, using the current composition. Multiplies every pixel for the shape or image by the globalAlpha property of the context. Composites the shape or image bitmap into the clipping region over the current canvas bitmap, using the current composition operator.
  • 14. Drawing Rectangles clearRect(double x, double y, double w, double h) strokeRect(double x, double y, double w, double h) fillRect(double x, double y, double w, double h) Colors and Transparency
  • 15. Gradients Linear Gradients createLinearGradient( double x0, double y0, double x1, double y1) Radial Gradients createRadialGradient( double x0, double y0, double r0, double x1, double y1, double r1)
  • 16. Patterns createPattern(HTMLImageElement | HTMLCanvasElement | HTMLVideoElement image, DOMString repetition)
  • 17. Shadows shadowColor: a CSS3 color shadowOffsetX: the horizontal offset in pixels from shape or text to the shadow shadowOffsetY: the vertical offset in pixels from shape or text to the shadow shadowBlur: a value, used in a Gaussian blur equation to smear the shadow Inset Shadows Negative values in OffSet
  • 20. Lines moveTo(x, y) lineTo(x, y) Drawing a Grid
  • 22. Line Caps and Joins
  • 23. Arcs and Circles arc(x, y, radius, startAngle, endAngle, counterClockwise) Rubberband Circles Rounded Rectangles (the arcTo() method)
  • 25. Bezier Curves quadraticCurveTo(double cpx, double cpy, double x, double y) Rounded corners with bezier curves
  • 26. Cubic Curves bezierCurveTo(double cpx, double cpy, double cp2x, double cp2y, double x, double y)
  • 27. Transformations rotate(double angleInRadians) scale(double x, double y) translate(double x, double y) Custom Transformations transform(double a, double b, double c, double d, double e, double f) setTransform(double a, double b, double c, double d, double e, double f)
  • 28. Text
  • 29. Methods rotate(double angleInRadians) scale(double x, double y) translate(double x, double y) Properties font textAlign textBaseline
  • 31. Text Patterns and Gradients
  • 32. Setting Font Properties font-style font-variant font-weight font-size line-height font-family
  • 37. The requestAnimationFrame() method function animate(time) { // Update and draw animation objects requestAnimationFrame(animate); // Sustain the animation } ... requestAnimationFrame(animate); // Start the animation long window.requestAnimationFrame(FrameRequestCallback callback) void window.cancelRequestAnimationFrame(long handle)
  • 38. Portable Animation loop The requestAnimationFrame() polyfill