HTML5 Canvas Cheat Sheet | Software Development | Software

HTML5 Canvas Cheat Sheet v1.

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

http://blog.nihilogic.dk/

Compositing
Attributes
Name globalAlpha Type float Default 1.0

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

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

Object

source-over

source-in

source-out

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

Methods
Return void void

Transformation
Methods
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)

copy

xor

Line styles
Attributes
Name lineWidth Type float Default 1.0

void

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

Image drawing
Methods
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)

miterLimit

float

10

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

Sign up to vote on this title
UsefulNot useful