You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
527 B
34 lines
527 B
2 years ago
|
ball = {
|
||
|
x: 100,
|
||
|
y: 100,
|
||
|
dx: -10,
|
||
|
dy: 10,
|
||
|
r : 80,
|
||
|
};
|
||
|
|
||
|
ball.update = function(){
|
||
|
this.y += this.dy;
|
||
|
this.x += ball.dx;
|
||
|
}
|
||
|
|
||
|
function setup() {
|
||
|
// put setup code here
|
||
|
createCanvas(400, 400);
|
||
|
frameRate(30);
|
||
|
|
||
|
}
|
||
|
|
||
|
function draw() {
|
||
|
// update code here
|
||
|
ball.dy -= (ball.y - height/2)/20;
|
||
|
ball.dx -= (ball.x - width/2)/20;
|
||
|
ball.update();
|
||
|
// put drawing code here
|
||
|
background(220);
|
||
|
stroke(0,0,255);
|
||
|
strokeWeight(4);
|
||
|
line(width/2, height/2, ball.x, ball.y);
|
||
|
noStroke();
|
||
|
ellipse(ball.x,ball.y,ball.r);
|
||
|
}
|