Draw Bezier curve without function

Hi!
I’m trying to understand bezier curve and i want to draw bezier without using ofBezier.
I use the formule you can find here:
http://en.wikipedia.org/wiki/B%C3%A9zier-curve
under “Explicit definition”.
I show you the code… i write in main draw function. It’s not a lot:

``````

ofSeedRandom(10);
ofPoint controls[3];
ofPoint actualPoint;
ofPoint oldPos;

int a;
int totElements = (int) sizeof(controls)/sizeof(ofPoint);

for(a = 0; a < totElements; a++)
{
controls[a].x = ofRandom(ofGetWidth());
controls[a].y = ofRandom(ofGetHeight());
}

actualPoint = controls[0];
for(float t = 0; t < 1; t += .4)
{
oldPos = actualPoint;

actualPoint.x = 0;
actualPoint.y = 0;

for(int i = 0; i < totElements; i++)
{
actualPoint.x += binCoef(totElements, i) * controls[i].x * pow((1 - t), totElements - i) * pow(t, i);
actualPoint.y += binCoef(totElements, i) * controls[i].y * pow((1 - t), totElements - i) * pow(t, i);
}

ofLine(oldPos.x, oldPos.y, actualPoint.x, actualPoint.y);
}

for(int i = 0; i < totElements; i++)
{
if(i == 0 || i == totElements - 1)
ofSetColor(255, 0, 0);
else
ofSetColor(255, 255, 0);
ofCircle(controls[i].x, controls[i].y, 10);
}

``````

And… voilà, it’s wrong. I don’t know what is wrong, but obviously it is.
Do you know where is the problem?
Thanks!