JavaScript - p5.js library - Bouncing Ball Animation

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Tried this in Brackets but it doesn't work. It seems to be the show function.

Code here:

html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Bouncing Ball</title>


<script


<script src="sketch.js"></script>
<script src="Ball.js"></script>
</head>
<body>
</body>
</html>

*sketch.js:*

var ball;
function setup() {

createCanvas(400, 400);

ball=new Ball(100, 100, 25);

}

function draw() {
background(55);
ball.show();
}

*Ball.js:*

function Ball(x, y, r){
this.x=x;
this.y=y;
this.r=r;
this.d=2*r;
this.xVelocity=-4;
this.yVelocity=3;

}
this.show=function(){
stroke(255);
strokeWeight(4);
noFill();
ellipse(this.x, this.y, this.d, this.d);

}
this.move=function(){
this.x+=this.xVelocity;
this.y+=this.yVelocity;
this.bounce();
}
this.bounce=function(){

this.xVelocity*=-1;

}

this.yVelocity*=-1;
}
}

galaktoza
visit shbcf.ru