Skip to content

Instantly share code, notes, and snippets.

@rkmathi
Last active December 21, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkmathi/6363808 to your computer and use it in GitHub Desktop.
Save rkmathi/6363808 to your computer and use it in GitHub Desktop.
あのあれ
<!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>
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