Last active
December 21, 2015 20:49
-
-
Save rkmathi/6363808 to your computer and use it in GitHub Desktop.
あのあれ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>hoge</title> | |
<meta charset="utf-8"> | |
<script src="hoge.js"></script> | |
</head> | |
<body> | |
<header> | |
<h1> | |
hoge | |
</h1> | |
</header> | |
<section> | |
<article> | |
<h2>fuga</h2> | |
<hr /> | |
<p> | |
<canvas height="480" id="c1" width="640"></canvas> | |
</p> | |
<hr /> | |
</article> | |
</section> | |
<footer> | |
<p>piyo</p> | |
</footer> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onload = function () { | |
var imgAry = [ | |
'1_indexed/00000351.png', | |
... | |
'1_indexed/00000445.png', | |
]; | |
var img = []; | |
var imgData = []; | |
var canvas = document.getElementById('c1'); | |
var ctx = canvas.getContext("2d"); | |
for (var i=0; i<imgAry.length; i++) { | |
img[i] = new Image(); | |
img[i].src = imgAry[i]; | |
} | |
console.log(img[i]); | |
ctx.drawImage(img[0], 0, 0); | |
var d = ctx.getImageData(0, 0, img[0].width, img[0].height); | |
imgData.push(d); | |
for (var j=1; j<imgAry.length; ++j) { | |
ctx.clearRect(0, 0, 640, 480); | |
ctx.putImageData(imgData[j-1], 0, 0); | |
ctx.drawImage(img[j], 0, 0); | |
imgData[j] = ctx.getImageData(0, 0, img[0].width, img[0].height); | |
} | |
ctx.clearRect(0, 0, 640, 480); | |
n = 0; | |
setInterval(function () { | |
ctx.clearRect(0, 0, 640, 480); | |
ctx.putImageData(imgData[n], 0, 0); | |
if (++n >= imgData.length) n = 0; | |
}, 50); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment