复制代码代码如下:
<html>
<body>
<canvas id = "canvas" style = "background-color: # 000;" />
<cript>
position de fonction (x, y) {
this.x = x;
this.y = y;
}
var canvas = document.getElementById ('canvas'),
ctx = canvas.getContext ('2d');
largeur = toile.Width,
hauteur = toile.Height;
ctx.fillStyle = "# ff0000";
ctx.font = "20px arial";
ctx.fillText ("妈妈", 10,50);
var pixs = ctx.getImagedata (0,0, largeur, hauteur) .data;
var pixels = new array ();
pour (var i = 0; i <pixs.length; i + = 4)
{
var r = pixs [i],
g = pixs [i + 1],
b = pixs [i + 2],
a = pixs [i + 3];
if (r! = 0 || g! = 0 || b! = 0) {
var x = i% 400;
var y = i / 400;
Pixels.push (nouvelle position (x, y));
}
}
</cript>
</docy>
</html>