HyperText Markup Language/Canvas

From Wikibooks, open books for an open world
Jump to: navigation, search

A Canvas allows for scriptable rendering of 2D shapes.A canvas can be rendered by JavaScript,which can be embedded into HTML. Rendering a Canvas:

<canvas id="e">This text will be displayed if the browser does not support canvas.</canvas>

JavaScript

var Canvas=document.getElementById("e");
var Context=Canvas.getContext("2d");
context.fillStyle="green";
context.fillRect(30,40,30,20);
context.strokeStyle="red";
context.strokeRect(30,40,30,20);
context.strokeText("Hello",30,40);
context.fillText("World",30,50);