Skip to content

tgs bola animasi

April 6, 2011

<html lang=”en”>
<head>
<span class=”hiddenSpellError” pre=””>Animasi</span> Bola
<style type=”text/css”>
canvas {
border: 0px solid black;
background-color:#000000;
}
</style>
// <![CDATA[javascript” >]]>
var cv;
var div;
var x = 10;
var y = 10;
var dx = 60;
var dy = 60;
var w = 400;
var h = 300;
function create(a,x,y,r) {
a.clearRect(0,0,w,h);
a.beginPath();
a.arc(x,y,r,0,Math.PI*2,true);
a.fillStyle=’red’;
a.fill();
a.strokeStyle=’red’;
a.stroke();
a.closePath();
}
function move() {
y += dy;
x += dx;
if (y > h || y < 0 || x > w || x < 0) {
if (y > h || y < 0) dy = -dy;
if (x > w || x < 0) dx = -dx;
div = document.createElement(‘div’);
div.innerHTML = ‘<audio src=”ball-sound.wav” autoplay autobuffer></audio>’;
document.getElementById(‘sound’).appendChild(div);
}
}
function animation() {
create(cv,x,y,20);
move();
}
function animate() {
cv = document.getElementById(‘canvas’).getContext(‘2d’);
if (cv == ‘undefined’) alert(‘canvas failed’);
return setInterval (animation,100);
}
</script>
</head>
<body onLoad=”animate();”>
<div id=”sound”><canvas id=”canvas” width=”400″ height=”300″></canvas></div>
</body>
</html>

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: