复制代码代码如下:
<html>
<тело>
<canvas id = "canvas" style = "fackground-color: #000;"/>
<Скрипт>
Положение функции (x, y) {
this.x = x;
this.y = y;
}
var canvas = document.getElementByid ('canvas'),
ctx = canvas.getContext ('2d');
ширина = canvas.width,
высота = холст. Хист;
ctx.fillstyle = "#ff0000";
ctx.font = "20px arial";
ctx.filltext ("妈妈", 10,50);
var pixs = ctx.getimagedata (0,0, ширина, высота) .data;
var pixels = new Array ();
для (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 (новая позиция (x, y));
}
}
</script>
</body>
</html>