2016年10月31日月曜日

HTML5 Canvas Cheat Sheet

Canvas element

Attributes

Name

Type

Default

width

unsigned long

300

height

unsigned long

150

Methods

Return

Name

string

toDataURL([Optional] string type, [Variadic] any args)

Object

getContext(string contextId)

2D Context

Attributes

Name

Type

Default

canvas

HTMLCanvasObject

[readonly]

Methods

Return

Name

void

save()

void

restore()

Transformation

Methods

Return

Name

void

scale(float xfloat y)

void

rotate(float angle)

void

translate(float xfloat y)

void

transform(float m11float m12float m21float m22floatdxfloat dy)

void

setTransform(float m11float m12float m21float m22float dxfloat dy)

Image drawing

Methods

Return

Name

void

drawImage(Object imagefloat dxfloat dy, [Optional] floatdwfloat dh)

Argument image can be of type HTMLImageElementHTMLCanvasElement or HTMLVideoElement.

void

drawImage(Object imagefloat sxfloat syfloat swfloatshfloat dxfloat dyfloat dwfloat dh)

Compositing

Attributes

Name

Type

Default

globalAlpha

float

1.0

globalCompositeOperation

string

source-over

Supports any of the following values:

  • source-over
  • source-in
  • source-out
  • source-atop
  • destination-over
  • destination-in
  • destination-out
  • destination-atop
  • lighter
  • copy
  • xor

Line styles

Attributes

Name

Type

Default

lineWidth

float

1.0

lineCap

string

butt

Supports any of the following values:

  • butt
  • round
  • square

lineJoin

string

miter

Supports any of the following values:

  • round
  • bevel
  • miter

miterLimit

float

10

Colors, styles and shadows

Attributes

Name

Type

Default

strokeStyle

any

black

fillStyle

any

black

shadowOffsetX

float

0.0

shadowOffsetY

float

0.0

shadowBlur

float

0.0

shadowColor

string

transparent black

Methods

Return

Name

CanvasGradient

createLinearGradient(float x0float y0float x1float y1)

CanvasGradient

createRadialGradient(float x0float y0float r0float x1float y1float r1)

CanvasPattern

createPattern(Object imagestring repetition)

image is HTMLImageElement or HTMLCanvasElement.

repetition supports any of the following values:

  • repeat (default)
  • repeat-x
  • repeat-y
  • no-repeat

CanvasGradient interface

Return

Name

void

addColorStop(float offsetstring color)

CanvasPattern interface

No attributes or methods.

Paths

Methods

Return

Name

void

beginPath()

void

closePath()

void

fill()

void

stroke()

void

clip()

void

moveTo(float xfloat y)

void

lineTo(float xfloat y)

void

quadraticCurveTo(float cpxfloat cpyfloat xfloat y)

void

bezierCurveTo(float cp1xfloat cp1yfloat cp2xfloatcp2yfloat xfloat y)

void

arcTo(float x1float y1float x2float y2float radius)

void

arc(float xfloat yfloat radiusfloat startAnglefloatendAngleboolean anticlockwise)

void

rect(float xfloat yfloat wfloat h)

boolean

isPointInPath(float xfloat y)

Text

Attributes

Name

Type

Default

font

string

10px sans-serif

textAlign

string

start

Supports any of the following values:

  • start
  • end
  • left
  • right
  • center

textBaseline

string

alphabetic

Supports any of the following values:

  • top
  • hanging
  • middle
  • alphabetic
  • ideographic
  • bottom

Methods

Return

Name

void

fillText(string textfloat xfloat y, [Optional] floatmaxWidth)

void

strokeText(string textfloat xfloat y, [Optional] floatmaxWidth)

TextMetrics

measureText(string text)

TextMetrics interface

Name

Type

Default

width

float

[readonly]

Rectangles

Methods

Return

Name

void

clearRect(float xfloat yfloat wfloat h)

void

fillRect(float xfloat yfloat wfloat h)

void

strokeRect(float xfloat yfloat wfloat h)

Pixel manipulation

Methods

Return

Name

ImageData

createImageData(float swfloat sh)

ImageData

getImageData(float sxfloat syfloat swfloat sh)

void

putImageData(ImageData imagedatafloat dxfloat dy, [Optional] float dirtyXfloat dirtyYfloat dirtyWidthfloatdirtyHeight)

ImageData interface

Name

Type

Default

width

unsigned long

[readonly]

height

unsigned long

[readonly]

data

CanvasPixelArray

[readonly]

CanvasPixelArray interface

Name

Type

Default

length

unsigned long

[readonly]

 

0 件のコメント:

コメントを投稿