P. 1
HTML5 Canvas Cheat Sheet

HTML5 Canvas Cheat Sheet

|Views: 7|Likes:
Published by mautik

More info:

Published by: mautik on Aug 11, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





HTML5 Canvas Cheat Sheet v1.

Canvas element
Name width height Type unsigned long unsigned long Default 300 150


Name globalAlpha Type float Default 1.0

Return string Name toDataURL( [Optional] string type, [Variadic] any args) getContext( string contextId)

globalCompositeOperation string source-over Supports any of the following values:





2D Context
Name canvas Type HTMLCanvasObject [readonly] source-atop Name save( ) restore( ) destination-out destination-atop lighter destination-over destination-in

Return void void

Return void void void void Name scale( float x, float y) rotate( float angle) translate( float x, float y) transform( float m11, float m12, float m21, float m22, float dx, float dy) setTransform( float m11, float m12, float m21, float m22, float dx, float dy)



Line styles
Name lineWidth Type float Default 1.0


lineCap string butt Supports any of the following values: butt round square

Image drawing
Return void Name lineJoin string miter Supports any of the following values: round bevel miter drawImage( Object image, float dx, float dy, [Optional] float dw, float dh) Argument "image" can be of type HTMLImageElement, HTMLCanvasElement or HTMLVideoElement void drawImage( Object image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)




float radius.0 0. float dirtyY.0 transparent black Text Attributes Name font Type string Default 10px sans-serif textAlign string start Supports any of the following values: [start.Colors. float y1.org/specs/web-apps/current-work/ (2009-05-04) . float sh) createImageData( ImageData getImageData( float sx. float r0. float x1. center] textBaseline string alphabetic Supports any of the following values: [top. float x. float y1. float y. float dirtyWidth. float y) quadraticCurveTo( float cpx. float radius ) arc( float x. [Optional] float maxWidth) strokeText( string text. float h) strokeRect( float x. float h) isPointInPath( float x. alphabetic. float dirtyHeight) void void ImageData interface width height data unsigned long unsigned long CanvasPixelArray [readonly] [readonly] [readonly] void CanvasPixelArray interface length unsigned long [readonly] void boolean Source: http://www. bottom] Methods Return CanvasGradient Name createLinearGradient( float x0. float cp1y. float y. HTMLCanvasElement or HTMLVideoElement "repetition" supports any of the following values: [repeat (default). left. right. middle. float dy. Paths Methods Return void void void void void void void void Name beginPath( ) closePath( ) fill( ) stroke( ) clip( ) moveTo( float x. float sh) putImageData( ImageData imagedata. repeat-x. float sy. float cpy. float startAngle. float y) lineTo( float x. string color) Rectangles Methods Return void Name clearRect( float x. float x1. hanging. float y1) CanvasGradient createRadialGradient( float x0. float y ) bezierCurveTo( float cp1x. [Optional] float maxWidth) measureText( string text) void TextMetrics TextMetrics interface width float [readonly] CanvasGradient interface void addColorStop( float offset. float w. float x. repeat-y. no-repeat] Methods Return void Name fillText( string text. float cp2y. float y. float y0. float y0. float x. float w. float x2. float y.0 0. float r1) CanvasPattern createPattern( Object image. float h) fillRect( float x. [Optional] float dirtyX. boolean anticlockwise ) rect( float x. end. float y. float y. float sw. float y. styles and shadows Attributes Name strokeStyle fillStyle shadowOffsetX shadowOffsetY shadowBlur shadowColor Type any any float float float string Default black black 0. float h) CanvasPattern interface No attributes or methods. string repetition) Argument "image" can be of type HTMLImageElement.whatwg. float dx. float w. float x. float y2. float cp2x. float y) void void Pixel manipulation Methods Return ImageData ImageData imagedata) ImageData void Name createImageData( float sw. float w. float y ) arcTo( float x1. ideographic. float endAngle.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->