SlideShare a Scribd company logo
HTML5 Canvas
The Future of
Graphics on the Web
Gary
2014/6/6
What is canvas?
An overview of canvas
• 2D drawing platform within the browser
• Uses nothing more than JavaScript and
HTML – no plugins
• Extensible through a JavaScript API
• Created by Apple for dashboard widgets
• Now openly developed as a W3C spec
Bitmap vs. vector
• Canvas is a bitmap system
– Everything is drawn as a single, flat, picture
– Changes require the whole picture to be redrawn
• SVG is a vector system
– Elements to be drawn are separate DOM objects
– They can be manipulated individually
• SVG isn’t part of HTML5
– Future isn’t as rosy as canvas
SVG? What is that?
SVG
• Scalable Vector Graphics
– An XML-based vector image format for two-
dimensional graphics with support for
interactivity and animation
– The SVG specification is an open standard
developed by the World Wide Web
Consortium (W3C) since 1999
Browser support
• Modern browsers
– Older versions of IE do not support canvas,
however Google and Mozilla plugins are
available
Internet Explorer Firefox Safari Chrome Opera
7.0 7.0 4.0 14.0 11.1
8.0 8.0 5.0 15.0 11.5
9.0 9.0 5.1 16.0 11.6
What is canvas for?
Data visualization
Animated graphics
Web applications
Games
Getting started
Created using the new HTML5 tag
<canvas height=“600” width=“800”></canvas>
HEIGHT AND WIDTH NEED TO BE SET EXPLICITY
(0,0)
Uses the standard screen-based
coordinate system
Everything is drawn onto the
2D rendering context (ctx)
CANVAS 2D rendering context
Use getContext()
to access the 2D rendering context
var canvas = document.getElementById(“canvas”);
var ctx = canvas.getContext(“2d”);
THIS IS YOUR FRIEND
ctx.fillStyle = ‘rgb(255, 0, 0)’;
ctx.strokeStyle = ‘rgba(0, 255, 0, 0.5)’;
fillStyle() and strokeStyle() define
the style of shapes to be drawn
USE RGBA FOR ALPHA
TRANSPARENCY
Simple shapes
Method Action
fillRect(x, y, w, h) Draws a rectangle using the current fill style
strokeRect(x, y, w, h) Draws the outline of a rectangle using the
current stroke style
clearRect(x, y, w, h) Clears all pixel within the given rectangle
Simple shapes are drawn without
effecting the current path
ctx.fillStyle = 'rgb(65, 60, 50)';
ctx.fillRect(25,50, 100, 100);
ctx.strokeStyle = 'rgb(65, 60, 50)';
ctx.strokeRect(130, 500, 40, 70);
500
130
Complex shapes & paths
• Path are a list of subpaths
• Subpaths are one or more points
connected by straight or curved lines
• Rendering context always has a current
path
• A new path should be created for each
individual shape
Complex shapes & paths
Method Action
beginPath() Resets the current path
closePath() Closes the current subpath and starts a new one
moveTo(x, y) Creates a new subpath at the given path
fill() Filles the subpath with the current fill style
stroke() Outlines the subpaths with the current strike
style
Complex shapes & paths
Method Action
lineTo(x, y) Draws a straight line from the previous point
rect(x, y, w, h) Adds a new closed rectangular subpath
arc(x, y, radius, startAngle,
endAngle, anticlockwise)
Adds a subpath along the circumference of the
described circle, within the angles defines
arcTo(x1, y1, x2, y2, radius) Adds a subpath connecting two points by an arc
of the defined radius
bezierCurveTo(cp1x, cp1y,
cp2x, cp2y, x, y)
Adds a cubic Bezier curve with the given control
points
quadraticCurveTo(cpx, cpy,
x, y)
Adds a quadratic Bezier curve with the given
control points
ctx.strokeStyle = ‘rgb(65, 60, 50)’
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.lineTo(100, 100);
ctx.stroke();
ctx.fillStyle = rgb(65, 60, 50)’
ctx.biginPath();
ctx.arc(100, 100, 30, 0, Math.PI*2, true);
ctx.fill();
ctx.strokeStyle = ‘rgb(65, 60, 50)’
ctx.beginPath();
ctx.moveTo(50, 50);
ctx.beizierCurveTo(70, 50, 130, 150, 150, 100);
ctx.stroke();
• arcTo(x1, y1, x2, y2, radius)
• Easy way to draw a rectangle with round corners,
or an arrow
• bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
• quadraticCurveTo(cpx, cpy, x, y)
Other cool stuff
• Text
• Shadows & blurring
• Line styles; width, cap, etc.
• Saving state of drawing context
• Transformations
Pixel manipulation
Images can be drawn onto the canvas
ctx.drawImage(image, dx, dy);
ctx.drawImage(image, dx, dy, dw. dh);
ctx.drawImage(image, sx, sy, sw, dx, dy, dw, dh);
Individual pixel values can be retrieved
ctx.getImageData(sx, sy, sw, sh)
Returns an array
of pixel values (RGBA)
Ambilight
Making things move
Harnessing the power
• Remember all the shapes on the canvas
• Move them, transform them, and make
them interact
• Redraw all the shapes in their new
positions
• Rinse and repeat, really quickly
The future of canvas
• It’s flexible and powerful
– Animation engines
– Pseudo 3D graphics
• Reading pixel values opens a lot of doors
• Integration with other HTML5 elements is
a killer feature
Is it a Flash killer?
Canvas vs. Flash
• Flash works in any browser that has a
plugin for it
– Adobe is no longer supporting Flash on mobile
devices
• Flash is an embedded SWF file which can
be difficult for search engines to parse
– Canvas is text based and it can all be read by
search engines
Thank you!

More Related Content

What's hot

Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
Vadim Spiridenko
 
The Canvas Tag
The Canvas TagThe Canvas Tag
The Canvas Tag
Dave Ross
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
dandylion13
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector Drawable
Phearum THANN
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
deanhudson
 
5 tips for your HTML5 games
5 tips for your HTML5 games5 tips for your HTML5 games
5 tips for your HTML5 games
Ernesto Jiménez
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
Kevin Hoyt
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
Blazing Cloud
 
Willustrator
WillustratorWillustrator
Willustrator
2da
 
Prototype UI Intro
Prototype UI IntroPrototype UI Intro
Prototype UI Intro
Juriy Zaytsev
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
gerbille
 
Lec2
Lec2Lec2
Interactive Graphics using Javascript, HTML5 and CSS3
Interactive Graphics using Javascript, HTML5 and CSS3Interactive Graphics using Javascript, HTML5 and CSS3
Interactive Graphics using Javascript, HTML5 and CSS3
Lee Lundrigan
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin Mullets
James Ward
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
Paul Smith
 
Iagc2
Iagc2Iagc2
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!
Phil Reither
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
livedoor
 
Building a Visualization Language
Building a Visualization LanguageBuilding a Visualization Language
Building a Visualization Language
jeresig
 

What's hot (20)

Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
The Canvas Tag
The Canvas TagThe Canvas Tag
The Canvas Tag
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
Android Vector Drawable
 Android Vector Drawable Android Vector Drawable
Android Vector Drawable
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
5 tips for your HTML5 games
5 tips for your HTML5 games5 tips for your HTML5 games
5 tips for your HTML5 games
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
Willustrator
WillustratorWillustrator
Willustrator
 
Prototype UI Intro
Prototype UI IntroPrototype UI Intro
Prototype UI Intro
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Lec2
Lec2Lec2
Lec2
 
Interactive Graphics using Javascript, HTML5 and CSS3
Interactive Graphics using Javascript, HTML5 and CSS3Interactive Graphics using Javascript, HTML5 and CSS3
Interactive Graphics using Javascript, HTML5 and CSS3
 
Kotlin Mullets
Kotlin MulletsKotlin Mullets
Kotlin Mullets
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
Iagc2
Iagc2Iagc2
Iagc2
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
 
Building a Visualization Language
Building a Visualization LanguageBuilding a Visualization Language
Building a Visualization Language
 

Similar to Html5 canvas

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
Anthony Starks
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
RutujRunwal1
 
Javascript Canvas API
Javascript Canvas APIJavascript Canvas API
Javascript Canvas API
Samuel Santos
 
CANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEventCANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEvent
민태 김
 
Drawing a Circle Three Ways: Generating Graphics for the Web
Drawing a Circle Three Ways: Generating Graphics for the WebDrawing a Circle Three Ways: Generating Graphics for the Web
Drawing a Circle Three Ways: Generating Graphics for the Web
Cloudinary
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using css
Dhairya Joshi
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
nimbleltd
 
Advanced CSS Tricks and Techniques
Advanced CSS Tricks and TechniquesAdvanced CSS Tricks and Techniques
Advanced CSS Tricks and Techniques
Robert Richelieu
 
Svg
SvgSvg
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
Anthony Starks
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
창석 한
 
Canvas
CanvasCanvas
Canvas
CanvasCanvas
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
 
5. SVG.pptx
5. SVG.pptx5. SVG.pptx
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
Robyn Overstreet
 
Animating an svg icon
Animating an svg iconAnimating an svg icon
Animating an svg icon
deepbidis
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
Thomas Fuchs
 
IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기
Reagan Hwang
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
Kevin Hoyt
 

Similar to Html5 canvas (20)

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
 
canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
Javascript Canvas API
Javascript Canvas APIJavascript Canvas API
Javascript Canvas API
 
CANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEventCANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEvent
 
Drawing a Circle Three Ways: Generating Graphics for the Web
Drawing a Circle Three Ways: Generating Graphics for the WebDrawing a Circle Three Ways: Generating Graphics for the Web
Drawing a Circle Three Ways: Generating Graphics for the Web
 
MTA managing the graphical interface by using css
MTA managing the graphical interface by using cssMTA managing the graphical interface by using css
MTA managing the graphical interface by using css
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Advanced CSS Tricks and Techniques
Advanced CSS Tricks and TechniquesAdvanced CSS Tricks and Techniques
Advanced CSS Tricks and Techniques
 
Svg
SvgSvg
Svg
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)CSS3 TTA (Transform Transition Animation)
CSS3 TTA (Transform Transition Animation)
 
Canvas
CanvasCanvas
Canvas
 
Canvas
CanvasCanvas
Canvas
 
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
 
5. SVG.pptx
5. SVG.pptx5. SVG.pptx
5. SVG.pptx
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Animating an svg icon
Animating an svg iconAnimating an svg icon
Animating an svg icon
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 

More from Gary Yeh

Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
Gary Yeh
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
Gary Yeh
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
Gary Yeh
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
Gary Yeh
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
Gary Yeh
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
Gary Yeh
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
Gary Yeh
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobile
Gary Yeh
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
Gary Yeh
 

More from Gary Yeh (10)

Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
Basic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.jsBasic Understanding and Implement of Node.js
Basic Understanding and Implement of Node.js
 
Run-time of Node.js : V8 JavaScript Engine
Run-time of Node.js: V8 JavaScript EngineRun-time of Node.js: V8 JavaScript Engine
Run-time of Node.js : V8 JavaScript Engine
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
jQuery Mobile and JavaScript
jQuery Mobile and JavaScriptjQuery Mobile and JavaScript
jQuery Mobile and JavaScript
 
JQuery mobile
JQuery mobileJQuery mobile
JQuery mobile
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
 
Git Workflow
Git WorkflowGit Workflow
Git Workflow
 

Recently uploaded

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 

Recently uploaded (20)

GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 

Html5 canvas

  • 1. HTML5 Canvas The Future of Graphics on the Web Gary 2014/6/6
  • 3. An overview of canvas • 2D drawing platform within the browser • Uses nothing more than JavaScript and HTML – no plugins • Extensible through a JavaScript API • Created by Apple for dashboard widgets • Now openly developed as a W3C spec
  • 4. Bitmap vs. vector • Canvas is a bitmap system – Everything is drawn as a single, flat, picture – Changes require the whole picture to be redrawn • SVG is a vector system – Elements to be drawn are separate DOM objects – They can be manipulated individually • SVG isn’t part of HTML5 – Future isn’t as rosy as canvas
  • 5. SVG? What is that?
  • 6. SVG • Scalable Vector Graphics – An XML-based vector image format for two- dimensional graphics with support for interactivity and animation – The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999
  • 7. Browser support • Modern browsers – Older versions of IE do not support canvas, however Google and Mozilla plugins are available Internet Explorer Firefox Safari Chrome Opera 7.0 7.0 4.0 14.0 11.1 8.0 8.0 5.0 15.0 11.5 9.0 9.0 5.1 16.0 11.6
  • 12. Games
  • 14. Created using the new HTML5 tag <canvas height=“600” width=“800”></canvas> HEIGHT AND WIDTH NEED TO BE SET EXPLICITY
  • 15. (0,0) Uses the standard screen-based coordinate system
  • 16. Everything is drawn onto the 2D rendering context (ctx) CANVAS 2D rendering context
  • 17. Use getContext() to access the 2D rendering context var canvas = document.getElementById(“canvas”); var ctx = canvas.getContext(“2d”); THIS IS YOUR FRIEND
  • 18. ctx.fillStyle = ‘rgb(255, 0, 0)’; ctx.strokeStyle = ‘rgba(0, 255, 0, 0.5)’; fillStyle() and strokeStyle() define the style of shapes to be drawn USE RGBA FOR ALPHA TRANSPARENCY
  • 19. Simple shapes Method Action fillRect(x, y, w, h) Draws a rectangle using the current fill style strokeRect(x, y, w, h) Draws the outline of a rectangle using the current stroke style clearRect(x, y, w, h) Clears all pixel within the given rectangle Simple shapes are drawn without effecting the current path
  • 20. ctx.fillStyle = 'rgb(65, 60, 50)'; ctx.fillRect(25,50, 100, 100); ctx.strokeStyle = 'rgb(65, 60, 50)'; ctx.strokeRect(130, 500, 40, 70); 500 130
  • 21. Complex shapes & paths • Path are a list of subpaths • Subpaths are one or more points connected by straight or curved lines • Rendering context always has a current path • A new path should be created for each individual shape
  • 22. Complex shapes & paths Method Action beginPath() Resets the current path closePath() Closes the current subpath and starts a new one moveTo(x, y) Creates a new subpath at the given path fill() Filles the subpath with the current fill style stroke() Outlines the subpaths with the current strike style
  • 23. Complex shapes & paths Method Action lineTo(x, y) Draws a straight line from the previous point rect(x, y, w, h) Adds a new closed rectangular subpath arc(x, y, radius, startAngle, endAngle, anticlockwise) Adds a subpath along the circumference of the described circle, within the angles defines arcTo(x1, y1, x2, y2, radius) Adds a subpath connecting two points by an arc of the defined radius bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) Adds a cubic Bezier curve with the given control points quadraticCurveTo(cpx, cpy, x, y) Adds a quadratic Bezier curve with the given control points
  • 24. ctx.strokeStyle = ‘rgb(65, 60, 50)’ ctx.beginPath(); ctx.moveTo(50, 50); ctx.lineTo(100, 100); ctx.stroke();
  • 25. ctx.fillStyle = rgb(65, 60, 50)’ ctx.biginPath(); ctx.arc(100, 100, 30, 0, Math.PI*2, true); ctx.fill();
  • 26. ctx.strokeStyle = ‘rgb(65, 60, 50)’ ctx.beginPath(); ctx.moveTo(50, 50); ctx.beizierCurveTo(70, 50, 130, 150, 150, 100); ctx.stroke();
  • 27. • arcTo(x1, y1, x2, y2, radius) • Easy way to draw a rectangle with round corners, or an arrow
  • 28. • bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) • quadraticCurveTo(cpx, cpy, x, y)
  • 29. Other cool stuff • Text • Shadows & blurring • Line styles; width, cap, etc. • Saving state of drawing context • Transformations
  • 31. Images can be drawn onto the canvas ctx.drawImage(image, dx, dy); ctx.drawImage(image, dx, dy, dw. dh); ctx.drawImage(image, sx, sy, sw, dx, dy, dw, dh);
  • 32. Individual pixel values can be retrieved ctx.getImageData(sx, sy, sw, sh) Returns an array of pixel values (RGBA)
  • 35. Harnessing the power • Remember all the shapes on the canvas • Move them, transform them, and make them interact • Redraw all the shapes in their new positions • Rinse and repeat, really quickly
  • 36. The future of canvas • It’s flexible and powerful – Animation engines – Pseudo 3D graphics • Reading pixel values opens a lot of doors • Integration with other HTML5 elements is a killer feature
  • 37. Is it a Flash killer?
  • 38. Canvas vs. Flash • Flash works in any browser that has a plugin for it – Adobe is no longer supporting Flash on mobile devices • Flash is an embedded SWF file which can be difficult for search engines to parse – Canvas is text based and it can all be read by search engines