HTML/Canvas

维基教科书,自由的教学读本

<canvas> tag允许脚本化地绘制2D形状。

绘制一个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);