Vec2d* bezier(Vec2d a,Vec2d b, Vec2d c,Vec2d d,float points){
//float points = 1000;
int p = points;
Vec2d array[p];
int i = 0;
glBegin(GL_LINE_STRIP);
for (float p = 0; p < 1.0 ; p=(p+(1.0/points))){
Vec2d e=((a * pow(1.0-p,3.0 ))+ (b * 3.0 * pow(1.0-p,2.0)*p) +(c * 3.0 * pow(p,2.0)*(1.0-p)) + (d * pow(p,3.0)));
glVertex2f(e.x, e.y);
array[i] = e; //put staarting vect in array
i++; //increment array
}
glEnd(); //A*b*b*b + B*3*b*b*p + C*3*b*p*p + D*p*p*p
return array;
}
void drawBezs(Vec2d * _a, int _b){
// printf( " hellowwwwww \n" );
float r= 1;
float g= 1;
float b= 1;
for (int i =0; i < _b; i++){
r = r - ((1.0/_b)); //color points
g = g - ((1.0/_b) ); //color points
b = b - ((1.0/_b) ); //color points
glColor3f( 1,1,b ); //color
if (i%4 == 0){
// printf( " hello %d \n",i );
bezier(_a[i],_a[i+1], _a[i+2],_a[i+3],1000.0);
}
}
}
////////////////////////************//////////////////////////////////
void displayFunc ( void ) //arg void returns void
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );//clears buffers(what buffers?) by setting bit mask or.
glColor3f( 1,1,1 );//sets color can add a alpha on end 255,255,255,255
//glRectf( mouseX-rectSize, mouseY-rectSize, mouseX+rectSize, mouseY+rectSize); //two arguments cords of perp corners this case based on mouse
Vec2d a(400.0,50.0); //bez starting points
Vec2d b(500.0,200.0);
Vec2d c(600.0,200.0);
Vec2d d(700.0,50.0);
Vec2d h(0.0,0.0);
Vec2d varray[500];
Vec2d * startArraay; //pointer to array
int count =0;
startArraay = bezier(a,b,c,d,132.0);// sets beging points using another bez curve
for( int i=0; i<500; i += 4 )
{
// start point
varray[ i ].x = startArraay[count].x;
varray[ i ].y = startArraay[count].y;
count++;
// control point 1
varray[ i+1].x = i+100 ;
varray[ i+1].y = 400;
// control point 2
varray[ i+2 ].x = i-100;
varray[ i+2 ].y = 200-i/4;
// end point
varray[ i+3].x = (startArraay[count].x)-300+i*1.5;//50+i*3;
varray[ i+3].y = (startArraay[count].y)+200; //100-i*1;
}
glPointSize(10.0);
// glBegin(GL_LINE_STRIP);
drawBezs(varray,500);
// glEnd();
glutPostRedisplay(); //tags the current window to be redisplayed or shown through the
//next iteration loop. will stop all animation
glutSwapBuffers(); //calls for the display of a the current buffer for the curretn window
// i assume to cut down on jerky motion
}