SlideShare a Scribd company logo
1 of 55
Download to read offline
Agenda
  • Getting started
  • Drawing
  • Charting
  • Images
  • Interaction
  • Animation
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
Curves




Quadratic Curve            Cubic Curve
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
Follow the Mouse
$( '#canvas' ).mousedown( function( evt ) {
  var coord = coordinate( evt, this );

  context.strokeStyle = color();
  context.moveTo( coord.x, coord.y );
  context.beginPath();

  $( '#canvas' ).mousemove( function( evt ) {
    var coord = coordinate( evt, this );

     context.lineTo( coord.x, coord.y );
     context.stroke();
  } ).mouseup( function( evt ) {
     $( '#canvas' ).unbind( 'mousemove' );
     $( '#canvas' ).unbind( 'mouseup' );
  } );
} );
Follow the Mouse
Follow the Finger
$( '#canvas' ).bind( ‘touchstart’, function( evt ) {
  evt.preventDefault();
  fill = color();

  $( '#canvas' ).bind( ‘touchmove’, function( evt ) {
    var touch = evt.originalEvent.touches[0];

     evt.preventDefault();
     context.fillStyle = radial(
       context, touch.clientX, touch.clientY );
     context.strokeStyle = 'rgba( 0, 255, 0, 0 )';
     context.beginPath();
     context.arc(
       touch.clientX, touch.clientY, 40, 0, Math.PI * 2, true );
     context.stroke();
     context.fill();
  } ).bind( ‘touchend’, function( evt ) {
     $( '#canvas' ).unbind( 'touchmove' );
     $( '#canvas' ).unbind( 'touchend' );
  } );
} );
Follow the Finger
Follow the Finger
Line Interpolation
Line Interpolation
var   xabs = Math.abs(   point1.x - point2.x );
var   yabs = Math.abs(   point1.y - point2.y );
var   xdiff = point2.x   - point1.x;
var   ydiff = point2.y   - point1.y;

var length = Math.sqrt( (
  Math.pow( xabs, 2 ) + Math.pow( yabs, 2 ) ) );
var steps = length / distance;
var xstep = xdiff / steps;
var ystep = ydiff / steps;

var newx, newy = 0;
var result = new Array();

for( var s = 0; s < steps; s++ ) {
  newx = point1.x + ( xstep * s );
  newy = point1.y + ( ystep * s );

    result.push( {x: newx, y: newy} );
}
Line Interpolation
Line Interpolation
PlotKit
MochiKit.DOM.addLoadEvent( function() {
  var canvas = MochiKit.DOM.getElement( 'chart' );
  var layout = new PlotKit.Layout( 'bar', {} );
  var plotter = new PlotKit.SweetCanvasRenderer(
    canvas,
    layout, {
    padding: {
       left: 40,
       right: 25,
       top: 25,
       bottom: 30
    },
  } );

  layout.addDataset( 'sqrt', [
     [0, 0], [1, 1], [2, 1.414], [3, 1.73], [4, 2]
  ] );
  layout.evaluate();
  plotter.render();
} );
PlotKit
RGraph
$( document ).ready( function() {
  var bar = null;
  var data = [
    280, 45, 133, 166, 84,
    259, 266, 960, 219, 311];

  bar = new RGraph.Bar( 'chart', data );
  bar.Set( 'chart.labels', [
     'Richard', 'Alex', 'Nick', 'Scott', 'Kjnell',
     'Doug', 'Charles', 'Michelle', 'Mark', 'Alison'
  ] );
  bar.Set( 'chart.gutter.left', 45 );
  bar.Set( 'chart.background.barcolor1',
     'rgba( 255, 255, 255, 1 )' );
  bar.Set( 'chart.background.barcolor2',
     'rgba( 255, 255, 255, 1 )' );
  bar.Set( 'chart.background.grid', true );
  bar.Set( 'chart.colors', ['rgba( 255, 0, 0, 1 )'] );
  bar.Draw();
} );
RGraph
jqPlot
var bar = null;
var data = new Array();
var value = null;

$.jqplot.config.enablePlugins = true;

$.jqplot( 'chart', [data], {
  legend: {show: true, location: 'nw'},
  title: 'Bar Chart',
  series: [
     {label: 'Random Numbers', renderer: $.jqplot.BarRenderer}
  ],
  axes: {
     xaxis: {renderer: $.jqplot.CategoryAxisRenderer},
     yaxis: {min: 0}
  }
} );
jqPlot
Real-Time

setInterval( function() {
  data.splice( 0, 1 );
  data.push( Math.floor( Math.random() * 25 ) );

  RGraph.Clear( canvas );
  bar.data = data;
  bar.Draw();
}, 500 );
Real-Time
Real-Time
Roll Your Own
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';
} );
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 );
} );
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
pixels = context.getImageData(
  0,
  0,
  640,
  480 );

for( var p = 0; p < pixels.data.length; p += 4 )
{
  red = pixels.data[p + 0];
  green = pixels.data[p + 1];
  blue = pixels.data[p + 2];
}
Pixel Dissecting
Beyond Pixels

var reader = new FileReader();

reader.onload = function( evt ) {
  var exif = new ExifInfo( evt.target.result );

     $( '<img src="data:image/jpeg;base64,' +
       btoa( exif.thumbnail ) +
       '"/>' )
       .appendTo( '#output' );
};

reader.readAsBinaryString( this.files[0] );
Beyond Pixels
Update on Interval
setInterval( function() {
  var time = new Date();

  context.clearRect( 0, 0, 300, 300 );

  context.rotate( ( ( 2 * Math.PI ) / 60 ) *
    time.getSeconds() +
    ( ( 2 * Math.PI ) / 60000 ) *
    time.getMilliseconds() );
  context.translate( 105, 0 );
  context.fillRect( 0, -12, 50, 24 );
  context.drawImage( earth, -12, -12 );
}, 100 );
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;
     }
} );
Tracking Points




    What’s clickable?
   How do you know?
   Canvas vs DOM...
Easel JS
var canvas = document.getElementById( 'game' );

stage = new Stage( canvas );

hole = new Bitmap( document.images[0] );
hole.x = 380;
hole.y = 120;
stage.addChild( hole );

ball = new Bitmap( document.images[1] );
ball.x = 20;
ball.y = 129;
stage.addChild( ball );

stage.update();

Ticker.setFPS( 24 );
Ticker.addListener( this );
Easel JS
Got Questions?

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

More Related Content

What's hot

Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"Austin Zheng
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 CanvasHenry Osborne
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 CanvasMindy McAdams
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
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
 
CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction Arulalan T
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsMichael Hackstein
 
In a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleIn a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleShay Davidson
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노Chiwon Song
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202Mahmoud Samir Fayed
 

What's hot (20)

Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
Swift, via "swift-2048"
Swift, via "swift-2048"Swift, via "swift-2048"
Swift, via "swift-2048"
 
Drawing with the HTML5 Canvas
Drawing with the HTML5 CanvasDrawing with the HTML5 Canvas
Drawing with the HTML5 Canvas
 
Introduction to HTML5 Canvas
Introduction to HTML5 CanvasIntroduction to HTML5 Canvas
Introduction to HTML5 Canvas
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
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
 
Supstat nyc subway
Supstat nyc subwaySupstat nyc subway
Supstat nyc subway
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction CDAT - graphics - vcs - xmgrace - Introduction
CDAT - graphics - vcs - xmgrace - Introduction
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.js
 
In a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation taleIn a galaxy far, far away - A procedural generation tale
In a galaxy far, far away - A procedural generation tale
 
[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노[3] 프로세싱과 아두이노
[3] 프로세싱과 아두이노
 
Graphical representation of Stack
Graphical representation of StackGraphical representation of Stack
Graphical representation of Stack
 
Myraytracer
MyraytracerMyraytracer
Myraytracer
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Ricky Bobby's World
Ricky Bobby's WorldRicky Bobby's World
Ricky Bobby's World
 
Css grid-layout
Css grid-layoutCss grid-layout
Css grid-layout
 
Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202The Ring programming language version 1.8 book - Part 65 of 202
The Ring programming language version 1.8 book - Part 65 of 202
 

Viewers also liked (12)

Wizard of Oz
Wizard of OzWizard of Oz
Wizard of Oz
 
Images of the Wizard of Oz
Images of the Wizard of OzImages of the Wizard of Oz
Images of the Wizard of Oz
 
Wizard Of Oz Yr6c
Wizard Of Oz Yr6cWizard Of Oz Yr6c
Wizard Of Oz Yr6c
 
Wizard Of Oz: Part I
Wizard Of Oz: Part IWizard Of Oz: Part I
Wizard Of Oz: Part I
 
The Wizard of Oz model of the outstanding teacher
The Wizard of Oz model of the outstanding teacherThe Wizard of Oz model of the outstanding teacher
The Wizard of Oz model of the outstanding teacher
 
The Contextual Wizard of Oz
The Contextual Wizard of OzThe Contextual Wizard of Oz
The Contextual Wizard of Oz
 
Life lessons from 'the wizard of oz'
Life lessons from 'the wizard of oz'Life lessons from 'the wizard of oz'
Life lessons from 'the wizard of oz'
 
The Yellow Brick Road of Leadership - Lessons from the Wizard of Oz
The Yellow Brick Road of Leadership - Lessons from the Wizard of OzThe Yellow Brick Road of Leadership - Lessons from the Wizard of Oz
The Yellow Brick Road of Leadership - Lessons from the Wizard of Oz
 
The rich symbolism of the Wizard of Oz
The rich symbolism of the Wizard of OzThe rich symbolism of the Wizard of Oz
The rich symbolism of the Wizard of Oz
 
The wizard of oz
The wizard of ozThe wizard of oz
The wizard of oz
 
5
55
5
 
The wizard of oz
The wizard of ozThe wizard of oz
The wizard of oz
 

Similar to Exploring Canvas

Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
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
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvassuitzero
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfKARTIKINDIA
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyistsdeanhudson
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentationsharp-blade
 
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
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017名辰 洪
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXStephen Chin
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphaelPippi Labradoodle
 
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
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developerAndrea Antonello
 

Similar to Exploring Canvas (20)

Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
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
 
Drawing on canvas
Drawing on canvasDrawing on canvas
Drawing on canvas
 
Canvas - The Cure
Canvas - The CureCanvas - The Cure
Canvas - The Cure
 
Canvas al ajillo
Canvas al ajilloCanvas al ajillo
Canvas al ajillo
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyists
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
SVGo workshop
SVGo workshopSVGo workshop
SVGo workshop
 
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
 
You will learn RxJS in 2017
You will learn RxJS in 2017You will learn RxJS in 2017
You will learn RxJS in 2017
 
Game dev 101 part 3
Game dev 101 part 3Game dev 101 part 3
Game dev 101 part 3
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFX
 
Creating masterpieces with raphael
Creating masterpieces with raphaelCreating masterpieces with raphael
Creating masterpieces with raphael
 
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
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Exploring Canvas

  • 1.
  • 2. Agenda • Getting started • Drawing • Charting • Images • Interaction • Animation
  • 3.
  • 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. Curves Quadratic Curve Cubic Curve
  • 11. Styles and Colors fillStyle strokeStyle orange #FFA500 rgb( 255, 165, 0 ) rgba( 255, 165, 0, 1 )
  • 12. 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 );
  • 13. 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 );
  • 14. 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 ); }
  • 16.
  • 17. Follow the Mouse $( '#canvas' ).mousedown( function( evt ) { var coord = coordinate( evt, this ); context.strokeStyle = color(); context.moveTo( coord.x, coord.y ); context.beginPath(); $( '#canvas' ).mousemove( function( evt ) { var coord = coordinate( evt, this ); context.lineTo( coord.x, coord.y ); context.stroke(); } ).mouseup( function( evt ) { $( '#canvas' ).unbind( 'mousemove' ); $( '#canvas' ).unbind( 'mouseup' ); } ); } );
  • 19. Follow the Finger $( '#canvas' ).bind( ‘touchstart’, function( evt ) { evt.preventDefault(); fill = color(); $( '#canvas' ).bind( ‘touchmove’, function( evt ) { var touch = evt.originalEvent.touches[0]; evt.preventDefault(); context.fillStyle = radial( context, touch.clientX, touch.clientY ); context.strokeStyle = 'rgba( 0, 255, 0, 0 )'; context.beginPath(); context.arc( touch.clientX, touch.clientY, 40, 0, Math.PI * 2, true ); context.stroke(); context.fill(); } ).bind( ‘touchend’, function( evt ) { $( '#canvas' ).unbind( 'touchmove' ); $( '#canvas' ).unbind( 'touchend' ); } ); } );
  • 23. Line Interpolation var xabs = Math.abs( point1.x - point2.x ); var yabs = Math.abs( point1.y - point2.y ); var xdiff = point2.x - point1.x; var ydiff = point2.y - point1.y; var length = Math.sqrt( ( Math.pow( xabs, 2 ) + Math.pow( yabs, 2 ) ) ); var steps = length / distance; var xstep = xdiff / steps; var ystep = ydiff / steps; var newx, newy = 0; var result = new Array(); for( var s = 0; s < steps; s++ ) { newx = point1.x + ( xstep * s ); newy = point1.y + ( ystep * s ); result.push( {x: newx, y: newy} ); }
  • 26.
  • 27. PlotKit MochiKit.DOM.addLoadEvent( function() { var canvas = MochiKit.DOM.getElement( 'chart' ); var layout = new PlotKit.Layout( 'bar', {} ); var plotter = new PlotKit.SweetCanvasRenderer( canvas, layout, { padding: { left: 40, right: 25, top: 25, bottom: 30 }, } ); layout.addDataset( 'sqrt', [ [0, 0], [1, 1], [2, 1.414], [3, 1.73], [4, 2] ] ); layout.evaluate(); plotter.render(); } );
  • 29. RGraph $( document ).ready( function() { var bar = null; var data = [ 280, 45, 133, 166, 84, 259, 266, 960, 219, 311]; bar = new RGraph.Bar( 'chart', data ); bar.Set( 'chart.labels', [ 'Richard', 'Alex', 'Nick', 'Scott', 'Kjnell', 'Doug', 'Charles', 'Michelle', 'Mark', 'Alison' ] ); bar.Set( 'chart.gutter.left', 45 ); bar.Set( 'chart.background.barcolor1', 'rgba( 255, 255, 255, 1 )' ); bar.Set( 'chart.background.barcolor2', 'rgba( 255, 255, 255, 1 )' ); bar.Set( 'chart.background.grid', true ); bar.Set( 'chart.colors', ['rgba( 255, 0, 0, 1 )'] ); bar.Draw(); } );
  • 31. jqPlot var bar = null; var data = new Array(); var value = null; $.jqplot.config.enablePlugins = true; $.jqplot( 'chart', [data], { legend: {show: true, location: 'nw'}, title: 'Bar Chart', series: [ {label: 'Random Numbers', renderer: $.jqplot.BarRenderer} ], axes: { xaxis: {renderer: $.jqplot.CategoryAxisRenderer}, yaxis: {min: 0} } } );
  • 33. Real-Time setInterval( function() { data.splice( 0, 1 ); data.push( Math.floor( Math.random() * 25 ) ); RGraph.Clear( canvas ); bar.data = data; bar.Draw(); }, 500 );
  • 37.
  • 38. 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'; } );
  • 39. 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 ); } );
  • 40. 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 ); } );
  • 41. Pixel Pushing context.drawImage( myImg, frame.x, frame.y, frame.width, frame.height );
  • 42. Pixel Slicing context.drawImage( myImg, frame.x, frame.y, frame.width, frame.height, 22, 21, frame.width, frame.height );
  • 43. Pixel Dissecting pixels = context.getImageData( 0, 0, 640, 480 ); for( var p = 0; p < pixels.data.length; p += 4 ) { red = pixels.data[p + 0]; green = pixels.data[p + 1]; blue = pixels.data[p + 2]; }
  • 45. Beyond Pixels var reader = new FileReader(); reader.onload = function( evt ) { var exif = new ExifInfo( evt.target.result ); $( '<img src="data:image/jpeg;base64,' + btoa( exif.thumbnail ) + '"/>' ) .appendTo( '#output' ); }; reader.readAsBinaryString( this.files[0] );
  • 47.
  • 48. Update on Interval setInterval( function() { var time = new Date(); context.clearRect( 0, 0, 300, 300 ); context.rotate( ( ( 2 * Math.PI ) / 60 ) * time.getSeconds() + ( ( 2 * Math.PI ) / 60000 ) * time.getMilliseconds() ); context.translate( 105, 0 ); context.fillRect( 0, -12, 50, 24 ); context.drawImage( earth, -12, -12 ); }, 100 );
  • 50. 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; } } );
  • 51.
  • 52. Tracking Points What’s clickable? How do you know? Canvas vs DOM...
  • 53. Easel JS var canvas = document.getElementById( 'game' ); stage = new Stage( canvas ); hole = new Bitmap( document.images[0] ); hole.x = 380; hole.y = 120; stage.addChild( hole ); ball = new Bitmap( document.images[1] ); ball.x = 20; ball.y = 129; stage.addChild( ball ); stage.update(); Ticker.setFPS( 24 ); Ticker.addListener( this );
  • 55. Got Questions? Kevin Hoyt khoyt@adobe.com Twitter: @krhoyt AIM,YIM: parkerkrhoyt http://blog.kevinhoyt.com