4. Use document.getElementById() to get a
reference to canvas
Call getContext('2d') on the canvas to get the
graphics context
Use the context to draw in the canvas
5. The Canvas API
Canvas attributes
width
height
Canvas methods
getContext()
toDataURL(type, quality)
toBlob(callback, type, args...)
6. The Canvas Context
Although the context provides 2d graphics context, the
Canvas specification embraces other types of contexts as
well; for example, a 3d context specification is already
well underway.
CanvasRenderingContext2D attributes
canvas miterLimit
fillStyle shadowBlur
font shadowColor
globalAlpha shadowOffsetX
globalComposite-Operation shadowOffsetY
lineCap strokeStyle
lineWidth textAlign
lineJoin textBaseline
7. Event Handling
Mouse Events
canvas.onmousedown = function(e) {
//mouse down event reaction
};
or
canvas.addEventListener('mousedown', function(e) {
//mouse down event reaction
});
13. The Drawing Model
Draws the shape or image into an infinite, transparent bitmap,
honoring the current fill, stroke, and line styles.
Draws the shadow from the shape or image into a second bitmap,
using the current context shadow settings.
Multiplies every shadow pixel's alpha component by the
globalAlpha property of the context.
Composites the shadow bitmap into the canvas clipped to the
clipping region, using the current composition.
Multiplies every pixel for the shape or image by the globalAlpha
property of the context.
Composites the shape or image bitmap into the clipping region
over the current canvas bitmap, using the current composition
operator.
14. Drawing Rectangles
clearRect(double x, double y, double w, double h)
strokeRect(double x, double y, double w, double h)
fillRect(double x, double y, double w, double h)
Colors and Transparency
17. Shadows
shadowColor: a CSS3 color
shadowOffsetX: the horizontal offset in pixels from shape
or text to the shadow
shadowOffsetY: the vertical offset in pixels from shape or
text to the shadow
shadowBlur: a value, used in a Gaussian blur equation to
smear the shadow
Inset Shadows
Negative values in OffSet