Vector | Raster |
---|---|
Scale Factor:
function RedrawVector(scale) { // clear the screen VectorCTX.clearRect(0,0,VectorCanvas.width, VectorCanvas.height); // save the state VectorCTX.save() // change the scale VectorCTX.scale(scale,scale); VectorCTX.translate(TX, TY); // draw the image VectorCTX.beginPath(); VectorCTX.moveTo(10,10); VectorCTX.lineTo(37,92); VectorCTX.lineTo(279, 294); VectorCTX.lineTo(10,10); VectorCTX.closePath(); VectorCTX.stroke(); // restore the state VectorCTX.restore(); return; }
function RedrawRaster(scale) { RasterCTX.clearRect(0,0,RasterCanvas.width, RasterCanvas.height); RasterCTX.save() RasterCTX.scale(scale,scale); RasterCTX.translate(TX, TY); RasterCTX.drawImage(RasterImage,0,0); RasterCTX.restore(); return; }
var RasterCanvas = document.getElementById('rasterCanvas'); ... RasterCanvas.tabIndex = 0;
RasterCanvas.tabIndex = 0; RasterCanvas.addEventListener("keydown", Keypress);
function Keypress(evnt) { switch (evnt.key) { case 'w': Up() break; case 'a': Left(); break; case 's': Down(); break; case 'd': Right(); break; } }