App
JavaScript Kodu
var canvas = document.querySelector('canvas');
var ctx = canvas.getContext('2d');
var pX = 0,
pY = 90;
vx = 5,
vy = -10;
// setInterval fonksiyon başlama
setInterval(function(){
ctx.fillStyle= "#000";
ctx.fillRect(0,0,545,400);
ctx.fillStyle = "white";
gravity=0.34;
if(pY > 180){
vy *= -0.5;
vx *= -0.5;
pY = 180;
}
if(pX>280){
vy *= -0.5;
vx *= -0.5;
pX = 280;
}
ctx.beginPath();
ctx.fillStyle="white";
c.rect(pX,pY,20,20);
ctx.fill();
pX +=2;
pY +=2;
vy +=gravity;
}, 30);
|