Week 6 Assignment

 

Problem2

Vec2d applyDistortion(Vec2d P, Vec2d F){

Vec2d V= P- F;

float len= V.getLength();

len /= 200.0;

float mag = 50.0;

float bell= mag*pow(2.0,-1.0*len*len);

V.normalize();

P= P+V*bell;
P=P+ V;
return P;

 

}
void drawDistorsion(){




int angle;
int numPoint=360;
float Rad= 160;

Vec2d P;
Vec2d center(mouseX,mouseY);
Vec2d forcet(200,200);
Vec2d force[4];
force[0].x=100;
force[0].y=100;
force[1].x=600;
force[1].y=500;
force[2].x=200;
force[2].y=400;
force[3].x=500;
force[3].y=200;
for( int i=0; i<4; i++){
drawPoint(force[i].x,force[i].y,4);

}

glBegin(GL_LINE_LOOP);
for(angle = 0; angle < numPoint; angle++)
{
float A = 2*PI /numPoint * angle;
P.x = cos(A) * Rad;
P.y = sin(A) * Rad;
P = P+ center;
glColor4f(0.5,0.2, 0.3,0.5);


for(int i=0; i<4; i++){
P=applyDistortion(P, force[i]);
}


glVertex2f(P.x, P.y);
}
glEnd();


}