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); }