So I am a canvas newbie and I've written some code trying to create an animation. I want to make a ball move with a parabola equation, everything works fine except for the fact that instead of having an animation I basically get a parabola made of arcs.
Here is the piece of code that I use for the animation:
// a b c are calculated in another function and they are used to calculate the parabola, x1 and y1 are the coordinates of the ball
function drawball(a,b,c,x1,y1){
canvas=document.getElementById("mycanvas");
ctx=canvas.getContext("2d");
ctx.beginPath();
ctx.arc(x1,y1,25,0,2*Math.PI);
ctx.stroke();
//stop when i get to the final point (x3 is a const)
if(x1<x3){
y1=a*(x1*x1)+b*x1+c; //parabola formula
x1++;
window.requestAnimationFrame(drawball(a,b,c,x1,y1));
}
}
In chrome's console I get this error:
Failed to execute 'requestAnimationFrame' on 'Window': The callback
provided as parameter 1 is not a function.
Thank you for your help!