SlideShare ist ein Scribd-Unternehmen logo
1 von 52
A blank slate to draw graphs, game graphics, video, or
other visual images on the fly.”
• 2D drawing tool within all modern browsers
• No downloads (plugins) required!
• Openly developed by the WC3 (WWW consortium)
Introduced by Apple, as
part of WebKit in 2004, to
show the power of
desktop apps within their
Safari browser.
Now a standard!
<canvas id=“myCanvas" width="150" height="150"></canvas>
• Only 2 attributes: Width & Height
• Default values for width and height: 300px x 150px
Older browsers may not support the <canvas>
element
Therefore, we insert fallback text, just in case it won’t
display
<canvas id=“myChart" width="150" height="150">
Current version of IE: 11
</canvas>
var canvas = document.getElementById('tutorial');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
// drawing code here
} else {
// canvas-unsupported code here:
Hey, you need to update your browser!
}
The canvas is a two-dimensional grid.
The coordinate (0, 0) is at the upper-
left corner of the canvas.
Along the X-axis, values increase from
left to right.
Along the Y-axis, values increase from
top to bottom.
var canvas = document.getElementById(‘myCanvas');
var ctx = canvas.getContext('2d');
var canvas = document.getElementById(“myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillRect(50, 25, 150, 100);
Parameters:
X: The x-coordinate of the upper-left corner of the rectangle
Y The y-coordinate of the upper-left corner of the rectangle
Width: The width of the rectangle, in pixels
Height: The height of the rectangle, in pixels
•fillStyle: can be a CSS color, a pattern, or a gradient. (Default color is black)
•strokeStyle: like fillStyle, but used for lines
•fillRect( x, y, width, height) draws a rectangle filled with the current fill style.
•strokeRect(x, y, width, height) draws an rectangle w/ current stroke style. Only draws edges.
•clearRect( x, y, width, height) clears the pixels in the specified rectangle.
<canvas id="myCanvas" width=“300" height="150"></canvas>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect (0, 0, 300, 150);
ctx.clearRect(20, 20, 100, 50);
<canvas id="myCanvas" width=200 height=120></canvas>
var canvas = document.getElementById('myCanvas');
var ctxt = canvas.getContext('2d');
ctx.fillStyle = '#000000'; // set color to black
ctx.fillRect(0, 0, 200, 40); // draw (200x40 pixel) rectangle at (0,0
ctx.fillStyle = '#FF0000'; // set color to red
ctx.fillRect(0, 40, 200, 40); // draw (200x40 pixel) rectangle at (0,40)
ctx.fillStyle = '#FFCC00'; // set color to gold
ctx.fillRect(0, 80, 200, 40); // draw (200x40 pixel) rectangle at (0,80)
• Scale(): Scales the current drawing, bigger or smaller
• Rotate(): Rotates current drawing
• Translate(): Moves the (0,0) position on the canvas
• Transform(): Replaces current transform matrix for current drawing
• setTransform(): Resets current transform matrix to the identity matrix, then runs
transform()
<canvas id="myCanvas" width="300" height="200"></canvas>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.rotate(20 * Math.PI / 180);
ctx.fillRect(50, 20, 100, 50);
Save & Restore context
Save & Restore context (cont’d)
To calculate from degrees to radians: degrees * Math.PI/180
<canvas id="myCanvas" width=“300" height=“300"></canvas>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.strokeRect(5, 5, 100, 30); // draw first rectangle
ctx.scale(2,2); // 2x width, 2x height
ctx.strokeRect(5, 5, 100, 30); // draw second triangle
http://www.w3schools.com/tags/playcanvas.asp?filename=playcanvas_transformb&preval=1,0,0,1,0,0
A – Scales the drawing horizontally
B – Skew the drawing horizontally
C- Skew the drawing vertically
D - Scale the drawing vertically
E – Moves the drawing horizontally
F – Moves the drawing vertically
<canvas id="myCanvas" width=“300" height=“300"></canvas>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillRect (10, 10, 100, 50);
ctx.translate(70, 70);
ctx.fillRect (10, 10, 100, 50);
Three steps are required:
1. Begin the path – beginPath()
2. Move the points – moveTo() or lineTo()
3. Stroke (outline) / Fill the path – stroke() or fill()
4. *Close the path – closePath()
*Note: When you call fill(), any open shapes are closed automatically, so you
don’t need to call closePath(). This is not true when you use stroke(), though.
Moves the “pencil” to the x, y coordinates
Doesn’t draw anything, but becomes part of the path
Think of it as lifting a pencil, then places it at this spot
Drags the “pencil” to the x, y coordinates
var canvas = document.getElementById(‘myCanvas');
if (canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.beginPath(); // starts drawing
ctx.moveTo(75,50); // First point (left)
ctx.lineTo(100,75); // Bottom point
ctx.lineTo(100,25); // Top point
ctx.fill(); // black is default
}
Unlike text on a webpage, there is no box model, so CSS layout
techniques are not available, such as:
- float, margin, padding, word wrap
Available attributes:
• font (style, font variant, weight, size, line height, family)
• textAlign (start, end, left, right, center)
• TextBaseline (top, hanging, middle, alphabetic, ideographic, bottom)
<canvas id=“myCanvas" width=“150” height=“100”></canvas>
var canvas = document.getElementById ('myCanvas'); // access the canvas object
var ctx = canvas.getContext ('2d'); // access the canvas context
ctx.fillRect (5,5,140,50); // fill rectangle with black color
ctx.fillStyle = 'red'; // set text color to 'red'
ctx.font = '40pt Arial'; // define the CSS font for writing text
ctx.fillText ('Text',1 0,50); // write the text 'Text‘
var canvas =document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var grd = ctx.createLinearGradient(0,0,170,0);
grd.addColorStop(0,"black");
grd.addColorStop(1,"white");
ctx.fillStyle=grd;
ctx.fillRect(0,0,150,100);
Smooth transition between two colors
CSS Gradients
Canvas gradients aren’t widely used
Instead, most developers prefer
#grad
{
background: -webkit-linear-gradient(left, white, black); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, white, black); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right white, black); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, white, black); /* Standard syntax */
}
Impact.js
Turbulenz
Paper.js
Canvas.js
Processing.js
EaselJS
HTML5 Canvas Tutorials
Link to HTML5 cheat sheet
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag

Weitere ähnliche Inhalte

Was ist angesagt?

Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
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
 
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 FlashThomas Fuchs
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...Sencha
 
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...Codemotion
 
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.v1Bitla Software
 
Mastering CSS Animations
Mastering CSS AnimationsMastering CSS Animations
Mastering CSS AnimationsGoodbytes
 
CSS Animations & Transitions
CSS Animations & TransitionsCSS Animations & Transitions
CSS Animations & TransitionsEdward Meehan
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Codemotion
 
Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Yuki Shimada
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive GraphicsBlazing Cloud
 
CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction Arulalan T
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSSChris Coyier
 

Was ist angesagt? (20)

Html5 canvas
Html5 canvasHtml5 canvas
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
 
Svg
SvgSvg
Svg
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
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
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
 
Work shop css3
Work shop css3Work shop css3
Work shop css3
 
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
Massimo Artizzu - The tricks of Houdini: a magic wand for the future of CSS -...
 
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
 
Mastering CSS Animations
Mastering CSS AnimationsMastering CSS Animations
Mastering CSS Animations
 
Canvas
CanvasCanvas
Canvas
 
CSS Animations & Transitions
CSS Animations & TransitionsCSS Animations & Transitions
CSS Animations & Transitions
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
 
Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)Ember.js Tokyo event 2014/09/22 (English)
Ember.js Tokyo event 2014/09/22 (English)
 
Interactive Graphics
Interactive GraphicsInteractive Graphics
Interactive Graphics
 
SVG overview
SVG overviewSVG overview
SVG overview
 
CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction
 
Using jQuery to Extend CSS
Using jQuery to Extend CSSUsing jQuery to Extend CSS
Using jQuery to Extend CSS
 

Ähnlich wie Advanced html5 diving into 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 gamedandylion13
 
SVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersSVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersPhil Reither
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
Canvas
CanvasCanvas
CanvasRajon
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman RodychPivorak MeetUp
 
An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasBen Hodgson
 
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 WebCloudinary
 
Javascript #10 : canvas
Javascript #10 : canvasJavascript #10 : canvas
Javascript #10 : canvasJean Michel
 
5 tips for your HTML5 games
5 tips for your HTML5 games5 tips for your HTML5 games
5 tips for your HTML5 gamesErnesto Jiménez
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suiteScott Ackerman
 
IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기Reagan Hwang
 
CANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEventCANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEvent민태 김
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasSteve Purkis
 
Canvas examples
Canvas examplesCanvas examples
Canvas examplesJadavsejal
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVGSpeedPartner GmbH
 

Ähnlich wie Advanced html5 diving into the canvas tag (20)

How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
SVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersSVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the Painters
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
Canvas
CanvasCanvas
Canvas
 
Plunge into HTML5 Canvas – Let’s begin
Plunge into HTML5 Canvas – Let’s beginPlunge into HTML5 Canvas – Let’s begin
Plunge into HTML5 Canvas – Let’s begin
 
Html canvas
Html canvasHtml canvas
Html canvas
 
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 HTML Canvas tips & tricks - Lightning Talk by Roman Rodych HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
HTML Canvas tips & tricks - Lightning Talk by Roman Rodych
 
An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 Canvas
 
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
 
Javascript #10 : canvas
Javascript #10 : canvasJavascript #10 : canvas
Javascript #10 : canvas
 
5 tips for your HTML5 games
5 tips for your HTML5 games5 tips for your HTML5 games
5 tips for your HTML5 games
 
An introduction to the create js suite
An introduction to the create js suiteAn introduction to the create js suite
An introduction to the create js suite
 
IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기
 
CANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEventCANVAS, SVG, WebGL, CSS3, WebEvent
CANVAS, SVG, WebGL, CSS3, WebEvent
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 Canvas
 
Canvas examples
Canvas examplesCanvas examples
Canvas examples
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 

Mehr von David Voyles

Developing games for consoles as an indie in 2019
Developing games for consoles as an indie in 2019Developing games for consoles as an indie in 2019
Developing games for consoles as an indie in 2019David Voyles
 
Developing for consoles as an indie in 2019
Developing for consoles as an indie in 2019Developing for consoles as an indie in 2019
Developing for consoles as an indie in 2019David Voyles
 
Overview Microsoft's ML & AI tools
Overview Microsoft's ML & AI toolsOverview Microsoft's ML & AI tools
Overview Microsoft's ML & AI toolsDavid Voyles
 
Intro to deep learning
Intro to deep learning Intro to deep learning
Intro to deep learning David Voyles
 
What is a Tech Evangelist?
What is a Tech Evangelist?What is a Tech Evangelist?
What is a Tech Evangelist?David Voyles
 
Microsoft on open source and security
Microsoft on open source and securityMicrosoft on open source and security
Microsoft on open source and securityDavid Voyles
 
Students: How to get started in the tech world
Students: How to get started in the tech worldStudents: How to get started in the tech world
Students: How to get started in the tech worldDavid Voyles
 
Students -- How to get started in the tech world
Students -- How to get started in the tech worldStudents -- How to get started in the tech world
Students -- How to get started in the tech worldDavid Voyles
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5David Voyles
 
How to win a hackathon - Penn APps 2015
How to win a hackathon - Penn APps 2015How to win a hackathon - Penn APps 2015
How to win a hackathon - Penn APps 2015David Voyles
 
Running, improving & maintaining a site in the real world
Running, improving & maintaining a site in the real worldRunning, improving & maintaining a site in the real world
Running, improving & maintaining a site in the real worldDavid Voyles
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applicationsDavid Voyles
 
Web standards and Visual Studio web tools
Web standards and Visual Studio web toolsWeb standards and Visual Studio web tools
Web standards and Visual Studio web toolsDavid Voyles
 
Build and deploy an ASP.NET applicaton
Build and deploy an ASP.NET applicatonBuild and deploy an ASP.NET applicaton
Build and deploy an ASP.NET applicatonDavid Voyles
 
Cluster puck99 postmortem
Cluster puck99 postmortemCluster puck99 postmortem
Cluster puck99 postmortemDavid Voyles
 
Joe Healy - How to set up your DreamSpark account
Joe Healy - How to set up your DreamSpark accountJoe Healy - How to set up your DreamSpark account
Joe Healy - How to set up your DreamSpark accountDavid Voyles
 
Joe Healy - Students as App Publishers
Joe Healy - Students as App PublishersJoe Healy - Students as App Publishers
Joe Healy - Students as App PublishersDavid Voyles
 
Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesDavid Voyles
 
An Introdouction to Venture Capital and Microsoft Ventures
An Introdouction to Venture Capital and Microsoft VenturesAn Introdouction to Venture Capital and Microsoft Ventures
An Introdouction to Venture Capital and Microsoft VenturesDavid Voyles
 

Mehr von David Voyles (20)

Developing games for consoles as an indie in 2019
Developing games for consoles as an indie in 2019Developing games for consoles as an indie in 2019
Developing games for consoles as an indie in 2019
 
Developing for consoles as an indie in 2019
Developing for consoles as an indie in 2019Developing for consoles as an indie in 2019
Developing for consoles as an indie in 2019
 
Overview Microsoft's ML & AI tools
Overview Microsoft's ML & AI toolsOverview Microsoft's ML & AI tools
Overview Microsoft's ML & AI tools
 
Intro to deep learning
Intro to deep learning Intro to deep learning
Intro to deep learning
 
What is a Tech Evangelist?
What is a Tech Evangelist?What is a Tech Evangelist?
What is a Tech Evangelist?
 
Microsoft on open source and security
Microsoft on open source and securityMicrosoft on open source and security
Microsoft on open source and security
 
Students: How to get started in the tech world
Students: How to get started in the tech worldStudents: How to get started in the tech world
Students: How to get started in the tech world
 
Students -- How to get started in the tech world
Students -- How to get started in the tech worldStudents -- How to get started in the tech world
Students -- How to get started in the tech world
 
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
Getting started with Emscripten – Transpiling C / C++ to JavaScript / HTML5
 
How to win a hackathon - Penn APps 2015
How to win a hackathon - Penn APps 2015How to win a hackathon - Penn APps 2015
How to win a hackathon - Penn APps 2015
 
ASP.NET 5
ASP.NET 5ASP.NET 5
ASP.NET 5
 
Running, improving & maintaining a site in the real world
Running, improving & maintaining a site in the real worldRunning, improving & maintaining a site in the real world
Running, improving & maintaining a site in the real world
 
Building web front ends using single page applications
Building web front ends using single page applicationsBuilding web front ends using single page applications
Building web front ends using single page applications
 
Web standards and Visual Studio web tools
Web standards and Visual Studio web toolsWeb standards and Visual Studio web tools
Web standards and Visual Studio web tools
 
Build and deploy an ASP.NET applicaton
Build and deploy an ASP.NET applicatonBuild and deploy an ASP.NET applicaton
Build and deploy an ASP.NET applicaton
 
Cluster puck99 postmortem
Cluster puck99 postmortemCluster puck99 postmortem
Cluster puck99 postmortem
 
Joe Healy - How to set up your DreamSpark account
Joe Healy - How to set up your DreamSpark accountJoe Healy - How to set up your DreamSpark account
Joe Healy - How to set up your DreamSpark account
 
Joe Healy - Students as App Publishers
Joe Healy - Students as App PublishersJoe Healy - Students as App Publishers
Joe Healy - Students as App Publishers
 
Using prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile servicesUsing prime[31] to connect your unity game to azure mobile services
Using prime[31] to connect your unity game to azure mobile services
 
An Introdouction to Venture Capital and Microsoft Ventures
An Introdouction to Venture Capital and Microsoft VenturesAn Introdouction to Venture Capital and Microsoft Ventures
An Introdouction to Venture Capital and Microsoft Ventures
 

Kürzlich hochgeladen

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Kürzlich hochgeladen (20)

Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Advanced html5 diving into the canvas tag

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. A blank slate to draw graphs, game graphics, video, or other visual images on the fly.”
  • 8. • 2D drawing tool within all modern browsers • No downloads (plugins) required! • Openly developed by the WC3 (WWW consortium)
  • 9. Introduced by Apple, as part of WebKit in 2004, to show the power of desktop apps within their Safari browser. Now a standard!
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. <canvas id=“myCanvas" width="150" height="150"></canvas> • Only 2 attributes: Width & Height • Default values for width and height: 300px x 150px
  • 17. Older browsers may not support the <canvas> element Therefore, we insert fallback text, just in case it won’t display <canvas id=“myChart" width="150" height="150"> Current version of IE: 11 </canvas>
  • 18. var canvas = document.getElementById('tutorial'); if (canvas.getContext){ var ctx = canvas.getContext('2d'); // drawing code here } else { // canvas-unsupported code here: Hey, you need to update your browser! }
  • 19. The canvas is a two-dimensional grid. The coordinate (0, 0) is at the upper- left corner of the canvas. Along the X-axis, values increase from left to right. Along the Y-axis, values increase from top to bottom.
  • 20. var canvas = document.getElementById(‘myCanvas'); var ctx = canvas.getContext('2d');
  • 21.
  • 22. var canvas = document.getElementById(“myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillRect(50, 25, 150, 100); Parameters: X: The x-coordinate of the upper-left corner of the rectangle Y The y-coordinate of the upper-left corner of the rectangle Width: The width of the rectangle, in pixels Height: The height of the rectangle, in pixels
  • 23.
  • 24. •fillStyle: can be a CSS color, a pattern, or a gradient. (Default color is black) •strokeStyle: like fillStyle, but used for lines •fillRect( x, y, width, height) draws a rectangle filled with the current fill style. •strokeRect(x, y, width, height) draws an rectangle w/ current stroke style. Only draws edges. •clearRect( x, y, width, height) clears the pixels in the specified rectangle.
  • 25. <canvas id="myCanvas" width=“300" height="150"></canvas> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "red"; ctx.fillRect (0, 0, 300, 150); ctx.clearRect(20, 20, 100, 50);
  • 26. <canvas id="myCanvas" width=200 height=120></canvas> var canvas = document.getElementById('myCanvas'); var ctxt = canvas.getContext('2d'); ctx.fillStyle = '#000000'; // set color to black ctx.fillRect(0, 0, 200, 40); // draw (200x40 pixel) rectangle at (0,0 ctx.fillStyle = '#FF0000'; // set color to red ctx.fillRect(0, 40, 200, 40); // draw (200x40 pixel) rectangle at (0,40) ctx.fillStyle = '#FFCC00'; // set color to gold ctx.fillRect(0, 80, 200, 40); // draw (200x40 pixel) rectangle at (0,80)
  • 27.
  • 28. • Scale(): Scales the current drawing, bigger or smaller • Rotate(): Rotates current drawing • Translate(): Moves the (0,0) position on the canvas • Transform(): Replaces current transform matrix for current drawing • setTransform(): Resets current transform matrix to the identity matrix, then runs transform()
  • 29.
  • 30. <canvas id="myCanvas" width="300" height="200"></canvas> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.rotate(20 * Math.PI / 180); ctx.fillRect(50, 20, 100, 50); Save & Restore context Save & Restore context (cont’d) To calculate from degrees to radians: degrees * Math.PI/180
  • 31. <canvas id="myCanvas" width=“300" height=“300"></canvas> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.strokeRect(5, 5, 100, 30); // draw first rectangle ctx.scale(2,2); // 2x width, 2x height ctx.strokeRect(5, 5, 100, 30); // draw second triangle
  • 32. http://www.w3schools.com/tags/playcanvas.asp?filename=playcanvas_transformb&preval=1,0,0,1,0,0 A – Scales the drawing horizontally B – Skew the drawing horizontally C- Skew the drawing vertically D - Scale the drawing vertically E – Moves the drawing horizontally F – Moves the drawing vertically
  • 33. <canvas id="myCanvas" width=“300" height=“300"></canvas> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillRect (10, 10, 100, 50); ctx.translate(70, 70); ctx.fillRect (10, 10, 100, 50);
  • 34.
  • 35. Three steps are required: 1. Begin the path – beginPath() 2. Move the points – moveTo() or lineTo() 3. Stroke (outline) / Fill the path – stroke() or fill() 4. *Close the path – closePath() *Note: When you call fill(), any open shapes are closed automatically, so you don’t need to call closePath(). This is not true when you use stroke(), though.
  • 36. Moves the “pencil” to the x, y coordinates Doesn’t draw anything, but becomes part of the path Think of it as lifting a pencil, then places it at this spot
  • 37. Drags the “pencil” to the x, y coordinates
  • 38. var canvas = document.getElementById(‘myCanvas'); if (canvas.getContext){ var ctx = canvas.getContext('2d'); ctx.beginPath(); // starts drawing ctx.moveTo(75,50); // First point (left) ctx.lineTo(100,75); // Bottom point ctx.lineTo(100,25); // Top point ctx.fill(); // black is default }
  • 39.
  • 40. Unlike text on a webpage, there is no box model, so CSS layout techniques are not available, such as: - float, margin, padding, word wrap Available attributes: • font (style, font variant, weight, size, line height, family) • textAlign (start, end, left, right, center) • TextBaseline (top, hanging, middle, alphabetic, ideographic, bottom)
  • 41. <canvas id=“myCanvas" width=“150” height=“100”></canvas> var canvas = document.getElementById ('myCanvas'); // access the canvas object var ctx = canvas.getContext ('2d'); // access the canvas context ctx.fillRect (5,5,140,50); // fill rectangle with black color ctx.fillStyle = 'red'; // set text color to 'red' ctx.font = '40pt Arial'; // define the CSS font for writing text ctx.fillText ('Text',1 0,50); // write the text 'Text‘
  • 42.
  • 43. var canvas =document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); var grd = ctx.createLinearGradient(0,0,170,0); grd.addColorStop(0,"black"); grd.addColorStop(1,"white"); ctx.fillStyle=grd; ctx.fillRect(0,0,150,100); Smooth transition between two colors
  • 44. CSS Gradients Canvas gradients aren’t widely used Instead, most developers prefer
  • 45. #grad { background: -webkit-linear-gradient(left, white, black); /* For Safari 5.1 to 6.0 */ background: -o-linear-gradient(right, white, black); /* For Opera 11.1 to 12.0 */ background: -moz-linear-gradient(right white, black); /* For Firefox 3.6 to 15 */ background: linear-gradient(to right, white, black); /* Standard syntax */ }
  • 46.
  • 48. Link to HTML5 cheat sheet

Hinweis der Redaktion

  1. You can have more than one <canvas> element on the same page. Each canvas will show up in the DOM, and each canvas maintains its own state. If you give each canvas an id attribute, you can access them just like any other element.
  2. Scripts can also check for support programatically by simply testing for the presence of the getContext() method.
  3. Default color is black
  4. The first line retrieves the DOM node for the <canvas> element by calling the document.getElementById() method. Once you have the element node, you can access the drawing context using its getContext() method.
  5. Visual Studio https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Canvas_tutorial/Basic_usage
  6. Default color is black http://jsfiddle.net/
  7. Default color is black
  8. http://jsfiddle.net/