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

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
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
 

Último (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
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...
 

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