SlideShare a Scribd company logo
1 of 31
Download to read offline
HTML5 Canvas
The canvas is
a 2d bitmap.
No   layers.
No   undo.
No   objects.
No   moving stuff.
http://rawkes.com/lab/google-balls-logo
http://blog.nihilogic.dk/2008/04/javascript-wolfenstein-3d.html
How  can I
 create a
 c anvas?
HTML
<canvas id="a">fallback txt</canvas>




JavaScript
var canvas =
  document.getElementsById('a');

var ctx = canvas.getContext('2d');
I draw
s quares.
con text
  ctx.fillStyle = 'blue';  he ight
  ctx.fillRect(0, 0, 150, 50);
               x y width




  ctx.strokeStyle = '#c66';
  ctx.lineWidth = 1;
  ctx.strokeRect(0.5, 60.5, 150, 50);
Iwant to
 d raw an
    image!
create image
var img = new Image();
img.onload = function() { w hen loaded
   ctx.drawImage(img, 0, 0);
};                     x  y
img.src = 'nakedrobot.png';
                          image url
how can you
  draw text?
css p roperties
ctx.font = 'bold 40px sans-serif';
ctx.fillText('hello kitty', 5, 40);
                            x  y

hello kitty
bring me
the pixels!
var w = canvas.width;
var h = canvas.height;
                                 new image array
var img = ctx.createImageData(w, h);
for (var x = 0; x < w; x++) {
    for (var y = 0; y < h; y++) {

        // each pixel has four values
        var idx = (x + y * w) * 4;

        // 0 red, 1 green, 2 blue, 3 alpha
        img.data[idx + 0] = x;
        img.data[idx + 1] = 255-x;
        img.data[idx + 2] = 0;
        img.data[idx + 3] = 255;
    }
}                                          result

ctx.putImageData(img, 0, 0);   write to canv
                                             as
http://media.chikuyonok.ru/ambilight/
close pixealte
http://desandro.com/resources/close-pixelate/
A nimation


 function ti
             ck() {
    doKeyboard(
                );
   updatePlaye
               r();
   doAI();
   draw();
  audio(); }
var fps = 3
            0;
setInterval
            (tick, 1000
                        /fps)   ;
get
       input




draw           update




every 30ms
function tick() {
	 doKeyboard();
	 updatePlayer();
	 doAI();
	 draw();
  audio();
}

var fps = 30;
setInterval(tick, 1000/fps);
How can
i Save an
Image?
var img = document.
  getElementsByTagName('img')[0];

var canvasImg =
  canvas.toDataURL("image/png");
                       returns “data:ima
                                         ge/png;base64,
img.src = canvasImg;           iVBORw0KGgoAAAA
                                                 NS
                               MgAAADICAYAAACt...” UhEU




  canvas      image
Browser
Support   67%
http://weavesilk.com/
Summary Canvas
<canvas> is a new 2d bitmap html element. you can draw primitives, images
and pixels. There are no layers or object. If a pixel gets a new color, the
old color is overwritten and lost.

A canvas is not “sandboxed” like flash and can be accessed and drawn on
with javascript.
Material Used
            Banksy “Have a Break” http://www.flickr.com/photos/loungerie/4109421950/

            Banksy “Flowing off” http://www.flickr.com/photos/loungerie/4109420324/

         Banksy “They’re Coming” http://www.flickr.com/photos/97041449@N00/4115205218/

      Bansky “Tourqay Robot” http://en.wikipedia.org/wiki/File:Banksy_Torquay_robot_crop.jpg

                  Banksy “You have got to be kidding me” http://www.banksy.co.uk/

        Banksy “follow your Dream” http://www.flickr.com/photos/thomashawk/6343586111/

          Banksy “nola” http://www.flickr.com/photos/eddiedangerous/3045255243/

 Banksy “Flower Pollard Street” http://www.flickr.com/photos/eddiedangerous/1800573742/

Banksy “what are you looking at?” http://www.flickr.com/photos/nolifebeforecoffee/124659356/

   Banksy “Man and Picture of a dog” http://www.flickr.com/photos/atomicshed/141462789/

   Banksy “Anti-Capitalism for sale” http://www.flickr.com/photos/jcodysimms/246024687/
Material Used
       3d teapot model http://resumbrae.com/ub/dms423_f08/10/

 Metal Teapot http://www.flickr.com/photos/11273631@N08/2867342497/

 furry teapot http://www.flickr.com/photos/11273631@N08/2867342461/

 Television Icon http://thenounproject.com/noun/television/#icon-No416

 Graphics Card http://www.flickr.com/photos/43779660@N00/218093887/

 Banksy “under the Carpet” http://www.flickr.com/photos/acb/147223287/

  Boxing http://www.flickr.com/photos/51035655711@N01/2826228569/

More Related Content

What's hot

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
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?Ankara JUG
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsJuriy Zaytsev
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?Eric Smith
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2dEric Smith
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScriptSam Cartwright
 
Pixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup SalzburgPixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup Salzburgwolframkriesing
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЮрий Сыровецкий
 
Machine Tags
Machine TagsMachine Tags
Machine Tagshchen1
 

What's hot (20)

5 tips for your HTML5 games
5 tips for your HTML5 games5 tips for your HTML5 games
5 tips for your HTML5 games
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
 
YUI for your Hacks
YUI for your Hacks YUI for your Hacks
YUI for your Hacks
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
Interactive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.jsInteractive web with Fabric.js @ meet.js
Interactive web with Fabric.js @ meet.js
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
Test driven game development silly, stupid or inspired?
Test driven game development   silly, stupid or inspired?Test driven game development   silly, stupid or inspired?
Test driven game development silly, stupid or inspired?
 
Test Driven Cocos2d
Test Driven Cocos2dTest Driven Cocos2d
Test Driven Cocos2d
 
Making Games in JavaScript
Making Games in JavaScriptMaking Games in JavaScript
Making Games in JavaScript
 
Pixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup SalzburgPixelplant - WebDev Meetup Salzburg
Pixelplant - WebDev Meetup Salzburg
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Зависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим ТалдыкинЗависимые типы в GHC 8. Максим Талдыкин
Зависимые типы в GHC 8. Максим Талдыкин
 
Three.js basics
Three.js basicsThree.js basics
Three.js basics
 
Machine Tags
Machine TagsMachine Tags
Machine Tags
 
3D everywhere
3D everywhere3D everywhere
3D everywhere
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 

Viewers also liked

An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to JqueryPhil Reither
 
WebGL - 3D in your Browser
WebGL - 3D in your BrowserWebGL - 3D in your Browser
WebGL - 3D in your BrowserPhil Reither
 
Responsive Web Design Patterns
Responsive Web Design PatternsResponsive Web Design Patterns
Responsive Web Design PatternsPhil Reither
 
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...Phil Reither
 

Viewers also liked (6)

An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to Jquery
 
WebGL - 3D in your Browser
WebGL - 3D in your BrowserWebGL - 3D in your Browser
WebGL - 3D in your Browser
 
Responsive Web Design Patterns
Responsive Web Design PatternsResponsive Web Design Patterns
Responsive Web Design Patterns
 
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
Docker: Fire your Sysadmin and use Docker to build, ship and run any app, any...
 
Web Design Trends 2014
Web Design Trends 2014Web Design Trends 2014
Web Design Trends 2014
 
Top 10 Web Design Trends for 2015
Top 10 Web Design Trends for 2015Top 10 Web Design Trends for 2015
Top 10 Web Design Trends for 2015
 

Similar to HTML5 Canvas - Let's Draw!

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreRemy Sharp
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?GCS2013
 
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
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Creating an Uber Clone - Part XXII.pdf
Creating an Uber Clone - Part XXII.pdfCreating an Uber Clone - Part XXII.pdf
Creating an Uber Clone - Part XXII.pdfShaiAlmog1
 
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
 
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
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Stegosploit - Blackhat Europe 2015
Stegosploit - Blackhat Europe 2015Stegosploit - Blackhat Europe 2015
Stegosploit - Blackhat Europe 2015Saumil Shah
 
Game Development With HTML5
Game Development With HTML5Game Development With HTML5
Game Development With HTML5Gil Megidish
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVDFramgia Vietnam
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with WingsRemy Sharp
 
Augmented reality in web rtc browser
Augmented reality in web rtc browserAugmented reality in web rtc browser
Augmented reality in web rtc browserALTANAI BISHT
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015Christian Heilmann
 
Canvas
CanvasCanvas
CanvasRajon
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIsRemy Sharp
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 

Similar to HTML5 Canvas - Let's Draw! (20)

HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
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
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Creating an Uber Clone - Part XXII.pdf
Creating an Uber Clone - Part XXII.pdfCreating an Uber Clone - Part XXII.pdf
Creating an Uber Clone - Part XXII.pdf
 
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
 
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
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Stegosploit - Blackhat Europe 2015
Stegosploit - Blackhat Europe 2015Stegosploit - Blackhat Europe 2015
Stegosploit - Blackhat Europe 2015
 
Game Development With HTML5
Game Development With HTML5Game Development With HTML5
Game Development With HTML5
 
Canvas in html5 - TungVD
Canvas in html5 - TungVDCanvas in html5 - TungVD
Canvas in html5 - TungVD
 
Browsers with Wings
Browsers with WingsBrowsers with Wings
Browsers with Wings
 
Augmented reality in web rtc browser
Augmented reality in web rtc browserAugmented reality in web rtc browser
Augmented reality in web rtc browser
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 
HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015HTML5 after the hype - JFokus2015
HTML5 after the hype - JFokus2015
 
Canvas
CanvasCanvas
Canvas
 
codebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIscodebits 2009 HTML5 JS APIs
codebits 2009 HTML5 JS APIs
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

HTML5 Canvas - Let's Draw!

  • 2.
  • 3.
  • 4.
  • 5. The canvas is a 2d bitmap.
  • 6. No layers. No undo. No objects. No moving stuff.
  • 9. How can I create a c anvas?
  • 10. HTML <canvas id="a">fallback txt</canvas> JavaScript var canvas = document.getElementsById('a'); var ctx = canvas.getContext('2d');
  • 12. con text ctx.fillStyle = 'blue'; he ight ctx.fillRect(0, 0, 150, 50); x y width ctx.strokeStyle = '#c66'; ctx.lineWidth = 1; ctx.strokeRect(0.5, 60.5, 150, 50);
  • 13. Iwant to d raw an image!
  • 14. create image var img = new Image(); img.onload = function() { w hen loaded ctx.drawImage(img, 0, 0); }; x y img.src = 'nakedrobot.png'; image url
  • 15. how can you draw text?
  • 16. css p roperties ctx.font = 'bold 40px sans-serif'; ctx.fillText('hello kitty', 5, 40); x y hello kitty
  • 18. var w = canvas.width; var h = canvas.height; new image array var img = ctx.createImageData(w, h); for (var x = 0; x < w; x++) { for (var y = 0; y < h; y++) { // each pixel has four values var idx = (x + y * w) * 4; // 0 red, 1 green, 2 blue, 3 alpha img.data[idx + 0] = x; img.data[idx + 1] = 255-x; img.data[idx + 2] = 0; img.data[idx + 3] = 255; } } result ctx.putImageData(img, 0, 0); write to canv as
  • 21. A nimation function ti ck() { doKeyboard( ); updatePlaye r(); doAI(); draw(); audio(); } var fps = 3 0; setInterval (tick, 1000 /fps) ;
  • 22. get input draw update every 30ms
  • 23. function tick() { doKeyboard(); updatePlayer(); doAI(); draw(); audio(); } var fps = 30; setInterval(tick, 1000/fps);
  • 24. How can i Save an Image?
  • 25. var img = document. getElementsByTagName('img')[0]; var canvasImg = canvas.toDataURL("image/png"); returns “data:ima ge/png;base64, img.src = canvasImg; iVBORw0KGgoAAAA NS MgAAADICAYAAACt...” UhEU canvas image
  • 27.
  • 29. Summary Canvas <canvas> is a new 2d bitmap html element. you can draw primitives, images and pixels. There are no layers or object. If a pixel gets a new color, the old color is overwritten and lost. A canvas is not “sandboxed” like flash and can be accessed and drawn on with javascript.
  • 30. Material Used Banksy “Have a Break” http://www.flickr.com/photos/loungerie/4109421950/ Banksy “Flowing off” http://www.flickr.com/photos/loungerie/4109420324/ Banksy “They’re Coming” http://www.flickr.com/photos/97041449@N00/4115205218/ Bansky “Tourqay Robot” http://en.wikipedia.org/wiki/File:Banksy_Torquay_robot_crop.jpg Banksy “You have got to be kidding me” http://www.banksy.co.uk/ Banksy “follow your Dream” http://www.flickr.com/photos/thomashawk/6343586111/ Banksy “nola” http://www.flickr.com/photos/eddiedangerous/3045255243/ Banksy “Flower Pollard Street” http://www.flickr.com/photos/eddiedangerous/1800573742/ Banksy “what are you looking at?” http://www.flickr.com/photos/nolifebeforecoffee/124659356/ Banksy “Man and Picture of a dog” http://www.flickr.com/photos/atomicshed/141462789/ Banksy “Anti-Capitalism for sale” http://www.flickr.com/photos/jcodysimms/246024687/
  • 31. Material Used 3d teapot model http://resumbrae.com/ub/dms423_f08/10/ Metal Teapot http://www.flickr.com/photos/11273631@N08/2867342497/ furry teapot http://www.flickr.com/photos/11273631@N08/2867342461/ Television Icon http://thenounproject.com/noun/television/#icon-No416 Graphics Card http://www.flickr.com/photos/43779660@N00/218093887/ Banksy “under the Carpet” http://www.flickr.com/photos/acb/147223287/ Boxing http://www.flickr.com/photos/51035655711@N01/2826228569/