SlideShare a Scribd company logo
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

More Related Content

PPTX
HTML CANVAS
PPTX
Googlevis examples
PPT
Scmad Chapter06
DOCX
treemap package in R and examples.
PDF
Matlab graphics
DOC
Java applet handouts
PPT
Texture mapping
PPTX
DPI 1 and DPI 2 Texture Mapping
HTML CANVAS
Googlevis examples
Scmad Chapter06
treemap package in R and examples.
Matlab graphics
Java applet handouts
Texture mapping
DPI 1 and DPI 2 Texture Mapping

What's hot (8)

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

Viewers also liked (12)

PDF
ベジェ曲線を書いてみた
PPTX
Dhtml sohaib ch
PPTX
Dynamic HTML (DHTML)
PPT
Basic Concepts of Animation
PPT
12 Concepts of Animation
PPSX
Animation techniques for CG students
PPT
Animation Techniques
PPTX
(Computer) Animation Technique
PPTX
Introduction to Animation
PPTX
Animation
PPTX
ANIMATION PPT
PDF
Computer Animation PowerPoint
ベジェ曲線を書いてみた
Dhtml sohaib ch
Dynamic HTML (DHTML)
Basic Concepts of Animation
12 Concepts of Animation
Animation techniques for CG students
Animation Techniques
(Computer) Animation Technique
Introduction to Animation
Animation
ANIMATION PPT
Computer Animation PowerPoint
Ad

Similar to Html5 Canvas Drawing and Animation (20)

PDF
Intro to HTML5 Canvas
PPTX
introduction of HTML canvas and styles .pptx
PDF
HTML5 Canvas - The Future of Graphics on the Web
PDF
SVGo: a Go Library for SVG generation
PPTX
HTML 5 Canvas & SVG
PPTX
canvas.pptx
PPT
Lecture on graphics
PPTX
HTML 5_Canvas
PPTX
canvas_1.pptx
PDF
Unit-1 basics of computer graphics
PPTX
HTML5 Canvas - Basics.pptx
PDF
SVGo workshop
PPTX
Css5 canvas
PPTX
Trident International Graphics Workshop 2014 4/5
PPTX
Intro to Canva
PPTX
Introduction to Canvas - Toronto HTML5 User Group
PDF
Introduction to Canvas - Toronto HTML5 User Group
PDF
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
PDF
Computer Graphics in Java and Scala - Part 1b
PDF
HTML5 Canvas
Intro to HTML5 Canvas
introduction of HTML canvas and styles .pptx
HTML5 Canvas - The Future of Graphics on the Web
SVGo: a Go Library for SVG generation
HTML 5 Canvas & SVG
canvas.pptx
Lecture on graphics
HTML 5_Canvas
canvas_1.pptx
Unit-1 basics of computer graphics
HTML5 Canvas - Basics.pptx
SVGo workshop
Css5 canvas
Trident International Graphics Workshop 2014 4/5
Intro to Canva
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
[Paper] GIRAFFE: Representing Scenes as Compositional Generative Neural Featu...
Computer Graphics in Java and Scala - Part 1b
HTML5 Canvas

More from Mindfire Solutions (20)

PDF
Physician Search and Review
PDF
diet management app
PDF
Business Technology Solution
PDF
Remote Health Monitoring
PDF
Influencer Marketing Solution
PPT
High Availability of Azure Applications
PPTX
IOT Hands On
PPTX
Glimpse of Loops Vs Set
ODP
Oracle Sql Developer-Getting Started
PPT
Adaptive Layout In iOS 8
PPT
Introduction to Auto-layout : iOS/Mac
PPT
LINQPad - utility Tool
PPT
Get started with watch kit development
PPTX
Swift vs Objective-C
ODP
Material Design in Android
ODP
Introduction to OData
PPT
Ext js Part 2- MVC
PPT
ExtJs Basic Part-1
PPT
Spring Security Introduction
Physician Search and Review
diet management app
Business Technology Solution
Remote Health Monitoring
Influencer Marketing Solution
High Availability of Azure Applications
IOT Hands On
Glimpse of Loops Vs Set
Oracle Sql Developer-Getting Started
Adaptive Layout In iOS 8
Introduction to Auto-layout : iOS/Mac
LINQPad - utility Tool
Get started with watch kit development
Swift vs Objective-C
Material Design in Android
Introduction to OData
Ext js Part 2- MVC
ExtJs Basic Part-1
Spring Security Introduction

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Strategies for Manufacturing Companies
PDF
Softaken Excel to vCard Converter Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
CHAPTER 2 - PM Management and IT Context
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Navsoft: AI-Powered Business Solutions & Custom Software Development
Odoo POS Development Services by CandidRoot Solutions
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
Design an Analysis of Algorithms I-SECS-1021-03
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Reimagine Home Health with the Power of Agentic AI​
PTS Company Brochure 2025 (1).pdf.......
Digital Strategies for Manufacturing Companies
Softaken Excel to vCard Converter Software.pdf

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