Thursday, November 8, 2012

HTML5 Canvas

Well, it looks like I need to revisit my syntax color copy for PS3.  I'll put it on the list.

But for now, Eric  (http://ericsowell.com/) did a presentation at NorthDallas.NET last night about the Canvas via Java.  Not .NET really, but I didn't even think to harass him about it.  So while he was talking I was trying to get it accessible from powershell.  I had the wrong version of IE accessible, but this morning in IE10.  I got it working.. Nothing rocket science, but I did manage to make an example as nothing showed up when I searched google for "HTML5 Canvas PowerShell"  This really is a bit of an edge case, I'll buy that.



$oie = new-object  -com internetexplorer.application
$oIE.navigate2("About:blank")
while ($oIE.busy) {
    sleep -milliseconds 50
}
$oIE.visible=$true

$doc = $oie.Document
$oIE.document.IHTMLDOcument2_write([string]'<body><canvas id="mycanvas" width="350" height="350">Test</canvas></body>')
while ($oIE.busy) {
    sleep -milliseconds 50
}
$canvas = $doc.getElementsByTagName("canvas")
$canvas = $doc.getElementByID("mycanvas")
$context  = $canvas.getContext("2d")
$context.clearRect(0, 0, $canvas.width, $canvas.height);
for ($i = 0; $i -lt 3; $i++)  {
            $context.fillStyle = "#95B524";
            $context.beginPath();
            $context.strokeStyle = "#fff";
            $context.lineWidth = 3;
            $context.arc(100,100,100,0,[math]::PI*2,$true);
            $context.closePath();
            $context.stroke();
            $context.fill();
        }