SlideShare uma empresa Scribd logo
1 de 44
Exploring Canvas


    Kevin Hoyt
    khoyt@adobe.com
    Twitter, AIM,YIM: parkerkrhoyt
    http://blog.kevinhoyt.com
Agenda
  • Getting started
  • Charting
  • Drawing
  • Interaction
  • Painting
  • Animation
Part #1:
Getting Started
Using the Canvas Tag
<canvas id="chart" width="150" height="150">
    Current stock price: $3.15 +0.15
</canvas>

<canvas id="clock" width="150" height="150">
    <img
         src="imagesclock.png"
         width="150"
         height="150"/>
</canvas>
Rendering Context
var canvas = document.getElementById( 'canvas' );
var context = null;

if( canvas.getContext )
{
  context = canvas.getContext( '2d' );
  // Drawing code here
} else {
  // Unsupported code here
}
Coordinate Space
      0
  0                          X

              y
          x




                          height
                  width
  Y
Drawing Paths
context.beginPath();

context.arc( 75, 75, 50, 0, Math.PI * 2, true );
context.moveTo( 110, 75 );
context.arc( 75, 75, 35, 0, Math.PI, false );
context.moveTo( 65, 65 );
context.arc( 60, 65, 5, 0, Math.PI * 2, true );
context.moveTo( 95, 65 );
context.arc( 90, 65, 5, 0, Math.PI * 2, true );

// context.closePath();
context.stroke();
// context.fill();
Understanding Lines
(0, 0)                    (0, 0)
                 (3, 1)                (3.5, 1)




                 (3, 5)                  (3.5, 5)
          1.0 width                1.0 width
Caps, Joints and Miters



   butt   round    width / 2
  round   bevel      x limit
 square   miter   from joint
Styles and Colors
         fillStyle
        strokeStyle




            orange
           #FFA500
     rgb( 255, 165, 0 )
   rgba( 255, 165, 0, 1 )
Gradients

// Start point and stop point
// Controls angle/direction of gradient
var fill = context.createLinearGradient( 0, 0, 0, 50 );

// 0 - 1 relative to gradient range
fill.addColorStop( 0, ‘#FFFFFF’ );
fill.addColorStop( 0.5, ‘#FFA500’ );
fill.addColorStop( 1, ‘#FFFFFF’ );

// Apply the fill style
context.fillStyle = fill;
context.fillRect( 0, 0, 50, 50 );
Gradients
// Inner circle point and radius
// Outer circle point and radius
// Not necessarily a single point
var fill = context.createRadialGradient(
    95, 15, 15,
    102, 20, 40
);

// 0 - 1 relative to gradient range
fill.addColorStop( 0, ‘#FFFFFF’ );
fill.addColorStop( 0.5, ‘#FFA500’ );
fill.addColorStop( 1, ‘#FFFFFF’ );

// Apply the fill style
context.fillStyle = fill;
context.fillRect( 0, 0, 50, 50 );
Text and Shadows
var canvas = document.getElementById( 'canvas' );
var ctx = null;

if( canvas.getContext )
{
    ctx = canvas.getContext( '2d' );

    ctx.shadowOffsetX = 2;
    ctx.shadowOffsetY = 2;
    ctx.shadowBlur = 2;
    ctx.shadowColor = 'rgba( 0, 0, 0, 0.5 )';

    ctx.font = '20px Times New Roman';
    ctx.fillStyle = 'black';
    ctx.fillText( 'Sample String', 5, 30 );
}
Shapes
Part #2:
Charting
PlotKit
jqPlot
RGraph
Part #3:
Drawing
Follow the Mouse
Saving
Saving with Flair
Looking Ahead
Part #4:
Interaction
Tracking Points




    What’s clickable?
   How do you know?
   Canvas vs DOM...
Curves




Quadratic Curve            Cubic Curve
Part #5:
Painting
Load From Server
Load From Server
var canvas = document.getElementById( 'canvas' );
var ctx = canvas.getContext( '2d' );
var img = null;

$( '#make' ).click( function( evt ) {
     img = new Image();
     img.onload = function() {
         ctx.drawImage( img, 0, 0 );
    };
     img.src = 'images/backdrop.png';
} );
Load From Server
Other Canvas
Other Canvas
var canvas = document.getElementById( 'lines' );
var ctx = canvas.getContext( '2d' );

ctx.beginPath();
ctx.moveTo( 30, 96 );
ctx.lineTo( 70, 66 );
ctx.lineTo( 103, 76 );
ctx.lineTo( 170, 15 );
ctx.stroke();

canvas = document.getElementById( 'canvas' );
ctx = canvas.getContext( '2d' );

$( '#lines' ).click( function( evt ) {
     ctx.drawImage( this, 0, 0 );
} );
Other Canvas
Embedded Data
Embedded Data

var canvas = document.getElementById( 'canvas' );
var ctx = canvas.getContext( '2d' );
var img = null;

$( '#embed' ).click( function( evt ) {
     img = new Image();
     img.src = 'data:image/png;base64,iVB...';
     ctx.drawImage( img, 0, 0 );
} );
Pixel Pushing

        context.drawImage(
            myImg,
            frame.x,
            frame.y,
            frame.width,
            frame.height );
Pixel Slicing
        context.drawImage(
            myImg,
            frame.x,
            frame.y,
            frame.width,
            frame.height,
            22,
            21,
            frame.width,
            frame.height );
Pixel Dissecting
Part #6:
Animation
Update on Interval
Tweening
JSTweener.addTween( position, {
    time: 3,
    transition: 'easeOutExpo',
    x: end.x,
    y: end.y,
    onUpdate: function() {
        context.clearRect( 0, 0, 640, 480 );
        // Draw updates to sprites
     },
    onComplete: function() {
        position = null;
        start = null;
        end = null;
     }
} );
Line Interpolation
Physics




 Box2D JS
Questions?

  Kevin Hoyt
  khoyt@adobe.com
  Twitter, AIM,YIM: parkerkrhoyt
  http://blog.kevinhoyt.com

Mais conteúdo relacionado

Mais procurados

UIWebViewでつくるUI
UIWebViewでつくるUIUIWebViewでつくるUI
UIWebViewでつくるUIcocopon
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015pixelass
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision DetectionJenchoke Tachagomain
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からYuichi Higuchi
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video gamedandylion13
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview민태 김
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"Austin Zheng
 
CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations Rob LaPlaca
 

Mais procurados (20)

UIWebViewでつくるUI
UIWebViewでつくるUIUIWebViewでつくるUI
UIWebViewでつくるUI
 
Proga 090525
Proga 090525Proga 090525
Proga 090525
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015Exploring fractals in CSS, @fronttrends, Warsaw, 2015
Exploring fractals in CSS, @fronttrends, Warsaw, 2015
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
cocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装からcocos2d 事例編 HungryMasterの実装から
cocos2d 事例編 HungryMasterの実装から
 
Proga 0629
Proga 0629Proga 0629
Proga 0629
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Html5 game programming overview
Html5 game programming overviewHtml5 game programming overview
Html5 game programming overview
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Proga 0518
Proga 0518Proga 0518
Proga 0518
 
Proga 0706
Proga 0706Proga 0706
Proga 0706
 
HTML 5_Canvas
HTML 5_CanvasHTML 5_Canvas
HTML 5_Canvas
 
Canvas - HTML 5
Canvas - HTML 5Canvas - HTML 5
Canvas - HTML 5
 
HTML CANVAS
HTML CANVASHTML CANVAS
HTML CANVAS
 
CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations
 

Semelhante a Exploring 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.v1Bitla Software
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfallurafashions98
 
Canvas
CanvasCanvas
CanvasRajon
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 
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
 
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagAdvanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagDavid Voyles
 
I need to create a page that looks like the picture The pro.pdf
I need to create a page that looks like the picture The pro.pdfI need to create a page that looks like the picture The pro.pdf
I need to create a page that looks like the picture The pro.pdfadianantsolutions
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvassuitzero
 
An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasBen Hodgson
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billynimbleltd
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
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
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
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 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
 

Semelhante a Exploring Canvas (20)

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
 
Canvas
CanvasCanvas
Canvas
 
Canvas
CanvasCanvas
Canvas
 
I need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdfI need to create a page looks like a picture. But it looks different.pdf
I need to create a page looks like a picture. But it looks different.pdf
 
Canvas
CanvasCanvas
Canvas
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 
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
 
Advanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tagAdvanced html5 diving into the canvas tag
Advanced html5 diving into the canvas tag
 
I need to create a page that looks like the picture The pro.pdf
I need to create a page that looks like the picture The pro.pdfI need to create a page that looks like the picture The pro.pdf
I need to create a page that looks like the picture The pro.pdf
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvas
 
An Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 CanvasAn Impromptu Introduction to HTML5 Canvas
An Impromptu Introduction to HTML5 Canvas
 
Rotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billyRotoscope inthebrowserppt billy
Rotoscope inthebrowserppt billy
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
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
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
Game dev 101 part 3
Game dev 101 part 3Game dev 101 part 3
Game dev 101 part 3
 
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 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
 

Último

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Exploring Canvas

  • 1. Exploring Canvas Kevin Hoyt khoyt@adobe.com Twitter, AIM,YIM: parkerkrhoyt http://blog.kevinhoyt.com
  • 2. Agenda • Getting started • Charting • Drawing • Interaction • Painting • Animation
  • 4. Using the Canvas Tag <canvas id="chart" width="150" height="150"> Current stock price: $3.15 +0.15 </canvas> <canvas id="clock" width="150" height="150"> <img src="imagesclock.png" width="150" height="150"/> </canvas>
  • 5. Rendering Context var canvas = document.getElementById( 'canvas' ); var context = null; if( canvas.getContext ) { context = canvas.getContext( '2d' ); // Drawing code here } else { // Unsupported code here }
  • 6. Coordinate Space 0 0 X y x height width Y
  • 7. Drawing Paths context.beginPath(); context.arc( 75, 75, 50, 0, Math.PI * 2, true ); context.moveTo( 110, 75 ); context.arc( 75, 75, 35, 0, Math.PI, false ); context.moveTo( 65, 65 ); context.arc( 60, 65, 5, 0, Math.PI * 2, true ); context.moveTo( 95, 65 ); context.arc( 90, 65, 5, 0, Math.PI * 2, true ); // context.closePath(); context.stroke(); // context.fill();
  • 8. Understanding Lines (0, 0) (0, 0) (3, 1) (3.5, 1) (3, 5) (3.5, 5) 1.0 width 1.0 width
  • 9. Caps, Joints and Miters butt round width / 2 round bevel x limit square miter from joint
  • 10. Styles and Colors fillStyle strokeStyle orange #FFA500 rgb( 255, 165, 0 ) rgba( 255, 165, 0, 1 )
  • 11. Gradients // Start point and stop point // Controls angle/direction of gradient var fill = context.createLinearGradient( 0, 0, 0, 50 ); // 0 - 1 relative to gradient range fill.addColorStop( 0, ‘#FFFFFF’ ); fill.addColorStop( 0.5, ‘#FFA500’ ); fill.addColorStop( 1, ‘#FFFFFF’ ); // Apply the fill style context.fillStyle = fill; context.fillRect( 0, 0, 50, 50 );
  • 12. Gradients // Inner circle point and radius // Outer circle point and radius // Not necessarily a single point var fill = context.createRadialGradient( 95, 15, 15, 102, 20, 40 ); // 0 - 1 relative to gradient range fill.addColorStop( 0, ‘#FFFFFF’ ); fill.addColorStop( 0.5, ‘#FFA500’ ); fill.addColorStop( 1, ‘#FFFFFF’ ); // Apply the fill style context.fillStyle = fill; context.fillRect( 0, 0, 50, 50 );
  • 13. Text and Shadows var canvas = document.getElementById( 'canvas' ); var ctx = null; if( canvas.getContext ) { ctx = canvas.getContext( '2d' ); ctx.shadowOffsetX = 2; ctx.shadowOffsetY = 2; ctx.shadowBlur = 2; ctx.shadowColor = 'rgba( 0, 0, 0, 0.5 )'; ctx.font = '20px Times New Roman'; ctx.fillStyle = 'black'; ctx.fillText( 'Sample String', 5, 30 ); }
  • 25. Tracking Points What’s clickable? How do you know? Canvas vs DOM...
  • 26. Curves Quadratic Curve Cubic Curve
  • 29. Load From Server var canvas = document.getElementById( 'canvas' ); var ctx = canvas.getContext( '2d' ); var img = null; $( '#make' ).click( function( evt ) { img = new Image(); img.onload = function() { ctx.drawImage( img, 0, 0 ); }; img.src = 'images/backdrop.png'; } );
  • 32. Other Canvas var canvas = document.getElementById( 'lines' ); var ctx = canvas.getContext( '2d' ); ctx.beginPath(); ctx.moveTo( 30, 96 ); ctx.lineTo( 70, 66 ); ctx.lineTo( 103, 76 ); ctx.lineTo( 170, 15 ); ctx.stroke(); canvas = document.getElementById( 'canvas' ); ctx = canvas.getContext( '2d' ); $( '#lines' ).click( function( evt ) { ctx.drawImage( this, 0, 0 ); } );
  • 35. Embedded Data var canvas = document.getElementById( 'canvas' ); var ctx = canvas.getContext( '2d' ); var img = null; $( '#embed' ).click( function( evt ) { img = new Image(); img.src = 'data:image/png;base64,iVB...'; ctx.drawImage( img, 0, 0 ); } );
  • 36. Pixel Pushing context.drawImage( myImg, frame.x, frame.y, frame.width, frame.height );
  • 37. Pixel Slicing context.drawImage( myImg, frame.x, frame.y, frame.width, frame.height, 22, 21, frame.width, frame.height );
  • 41. Tweening JSTweener.addTween( position, { time: 3, transition: 'easeOutExpo', x: end.x, y: end.y, onUpdate: function() { context.clearRect( 0, 0, 640, 480 ); // Draw updates to sprites }, onComplete: function() { position = null; start = null; end = null; } } );
  • 44. Questions? Kevin Hoyt khoyt@adobe.com Twitter, AIM,YIM: parkerkrhoyt http://blog.kevinhoyt.com

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n