Has anyone encountered a clear guide to using canvas from html5. I tried some examples, it seems, everything works out, but I did not get an understanding.
UPD1: Just selectively read it. A piece of google mail checker'a:
function animateFlip() { rotation += 1/animationFrames; drawIconAtRotation(); if (rotation <= 1) { setTimeout("animateFlip()", animationSpeed); } else { rotation = 0; drawIconAtRotation(); chrome.browserAction.setBadgeBackgroundColor({color:[208, 0, 24, 255]}); } } function ease(x) { return (1-Math.sin(Math.PI/2+x*Math.PI))/2; } function drawIconAtRotation() { canvasContext.save(); canvasContext.clearRect(0, 0, canvas.width, canvas.height); canvasContext.translate( Math.ceil(canvas.width/2), Math.ceil(canvas.height/2)); canvasContext.rotate(2*Math.PI*ease(rotation)); canvasContext.drawImage(loggedInImage, -Math.ceil(canvas.width/2), -Math.ceil(canvas.height/2)); canvasContext.restore(); chrome.browserAction.setIcon({imageData:canvasContext.getImageData(0, 0, canvas.width,canvas.height)}); }
I'm trying to figure out how the drawIconAtRotation
function drawIconAtRotation
. Especially I do not understand what the ease()
function is.
UPD2: If you dig even deeper, then I do not understand, the actions themselves in drawIconAtRotation
. Why do I need to save the state with save()
, how does translate()
, rotate()
? I found an article on Habré about transformation, but I still haven’t figured it out = (