void distort( Vec2d* _circle, int CPoints, Vec2d* Points, int numPoints, float* distortStrength) {

     float distortX, distortY;


     // for each point, add distort effect of every distort pre-set point

     for( int i=0;i<CPoints;i++ ) {

          for( int j=0;j<numPoints;j++ ) {

               

               // get distort vector ( direction, length )

Vec2d distortVec = _circle[i] - Points[j]; // the two vectors

float distance = distortVec.vectorLength();//gets the dif 

distortVec.normalize(); //divides out all length just leaving base ratio vector

  float power = 200/(distance*distance);

distortX += distortVec.x * distortStrength[j] * 2 * power;

               distortY += distortVec.y * distortStrength[j] * 2 * power;

          }    

          

          // distort pos of the original point

            _circle[i].x += distortX;

            _circle[i].y += distortY;

          distortX = 0;//reset

                  distortY = 0;

    }


    

     // draw distorted circle

     glColor3f( 0,0,1 );

     glBegin( GL_LINE_LOOP );

     for( int i=0;i<CPoints;i++ ) {

               glVertex2f( _circle[i].x, _circle[i].y );

               }

     glEnd();

 

  // draw distortion points on top

     glColor3f( 0,0,0 );

     glPointSize( 5.0 );

     glBegin( GL_POINTS );

     for( int i=0;i<numPoints;i++ ) {

          glVertex2f( Points[i].x, Points[i].y );

     }

     glEnd();


}


void drawFlexedCircle ( void ) {


    

     float angle;

     float radius = 200;

Vec2d circlePoint[360];

     Vec2d Center = Vec2d( windowW/2, windowH/2 );

     glColor3f( 0,1,1 );

    // glBegin( GL_LINE_LOOP );

     

     for(int i=0;i<360;i++) { 

             angle =  i; // angle of each point

             circlePoint[i] = Vec2d( radius * d_cos(angle)+Center.x, radius*d_sin(angle)+Center.y );

                                   

             glVertex2f( circlePoint[i].x, circlePoint[i].y );

     }        

    // glEnd();     

     

     Vec2d disPoints[10] = {  Vec2d(300,350), Vec2d(150,300), Vec2d(200,450), Vec2d(300,500), Vec2d(400,400),Vec2d(550,150)};

     float force[10] = {  300, 125,  20, 150, 42, 100 };


     distort( circlePoint, 360, disPoints, 6, force );


}