HTML5 Canvas Code Examples

Hello Canvas

run

Drawing a blue rectangle. This example demonstrates:

Smiley Face

run

Drawing a smiley face. This example demonstrates:

Hello Text!

run

Drawing the text "Hello Text!" in gray with a black stroke. This example demonstrates:

The Sierpinski Triangle

run

Drawing the Sierpinski Triangle. This example demonstrates:

See also the Sierpinski Carpet

Digital Clock

run

Drawing the text representing the time of day. This example demonstrates:

Mouse Follower

run

Drawing a circle that follows the mouse. This example demonstrates:

Bouncing Ball

run

A bouncing ball that can be swung around with the mouse. This example demonstrates:

Bouncing Balls

run

Many bouncing balls that can be swung around with the mouse. This example demonstrates:

Tree Fractal

run

An interactive tree fractal. This example demonstrates:

Starfield

run

A starfield with stars moving toward you. The mouse controls the focal length. This example demonstrates:

Wave Simulation

run

A 1-dimensional numeric simulation of the Wave equation. This example demonstrates:

2D Wave Simulation

run

A 2-dimensional numeric simulation of the Wave equation. This example demonstrates:

Graphing Calculator

run

A grapher that plots equations. This example demonstrates:

Multi-touch Fingerpainting

run (supports multi-touch in iOS devices)

Multi-touch fingerpainting, where each touch gets its own random color. This example demonstrates:

Multi-touch Air Hockey

run (supports multi-touch in iOS devices)

An air hockey game for the iPad. This example demonstrates:

Game of Life

run

Conways Game of Life, in CoffeeScript. View Source