Problem 1.
Create a function that takes as input a number of steps, and draws that many points, evenly spaced between the last two mouse clicks.
// global variables for W4_1
Vec2d startPoint = Vec2d( -1,-1 );
Vec2d endPoint = Vec2d ( -1,-1 );
// LERP
Vec2d LERP ( Vec2d A, Vec2d B, float p ) {
return A*(1.0-p) + B*p;
}
// function
void drawEvenlySpacedLine( int numPoints ) {
if ( startPoint.x >= 0 && endPoint.x >=0 ) { // draw after two clicks
glPointSize( 3 );
glBegin( GL_POINTS );
for( int i=0; i<=numPoints; i++ ) { // steps of numPoints
Vec2d C = LERP( startPoint, endPoint, (float)i/numPoints);
glVertex2f ( C.x, C.y );
}
glEnd();
}
}
// called in displayFunc()
drawEvenlySpacedLine(10);
// add to mouseDownFunc()
if (endPoint.y != mouseX && endPoint.y != mouseY ) {
startPoint = endPoint;
endPoint.x = mouseX;
endPoint.y = mouseY;
}
: 10 steps
Problem 2.
Create a function that takes as input a number of steps, and draws that many intermediate shapes between a start shape and an end shape. The start shape and end shape should be defined by an array of vectors (i.e points), and should have the same number of points. Extra credit for those who can make this work for two shapes with an unequal number of points.
Problem 4.
Create a function that takes as input an array of points (Vec2d *) and the number of points in that array (int), and draws a shape composed of several consecutive Bezier curves.
Problem 6.
Extra credit: make a bezier drawing tool that works just like the one in Adobe Illustrator.
// global varibales for W4_5
int bezierStatus = 0;
Vec2d A, B, C, D;
// guideline for bezier curve
void drawGuideLine ( Vec2d Center, Vec2d Point ) {
glColor3f ( 0,0,1 );
glPointSize(3);
glBegin( GL_POINTS ); // points
glVertex2f ( Center.x, Center.y );
glVertex2f ( Point.x, Point.y );
glEnd();
glLineWidth( 1 );
glBegin( GL_LINES ); // lines
glVertex2f ( Point.x, Point.y );
glVertex2f ( Center.x, Center.y );
glEnd();
}
// draw Bezier Curve like Adobe Illustrator
void drawBezier ( void ) {
switch( bezierStatus ) {
case 0:
break;
case 1:
B = Vec2d( mouseX,mouseY );
drawGuideLine( A, B );
drawGuideLine( A, A*2-B );
break;
case 2:
drawGuideLine( A, B );
drawGuideLine( A, A*2-B );
break;
case 3:
drawGuideLine( A, B );
D = Vec2d( mouseX,mouseY );
drawGuideLine( C, D );
drawGuideLine( C, C*2-D );
drawCubicBezierCurve( A,B,C*2-D,C );
break;
case 4:
drawGuideLine( A, B );
drawGuideLine( C, D );
drawGuideLine( C, C*2-D );
glColor3f( 0,0,0 );
glLineWidth( 2 );
drawCubicBezierCurve( A,B,C*2-D,C );
break;
case 5:
glColor3f( 0,0,0 );
glLineWidth( 2 );
drawCubicBezierCurve( A,B,C*2-D,C );
break;
default:
break;
}
}
// in mouseDownFunc()
// reset
if ( button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN ) {
bezierStatus = 0;
}
// steps of drawing bezier curve
if ( bezierStatus == 0 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
A = Vec2d( mouseX,mouseY );
bezierStatus = 1;
}
if ( bezierStatus == 1 && button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
bezierStatus = 2;
}
if ( bezierStatus == 2 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
C = Vec2d( mouseX,mouseY );
bezierStatus = 3;
}
if ( bezierStatus == 3 && button == GLUT_LEFT_BUTTON && state == GLUT_UP ) {
bezierStatus = 4;
}
if ( bezierStatus == 4 && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) {
bezierStatus = 5;
}
: step 1 of bezier drawing tool
: step 2
: step 3
video of bezier drawing tool
Problem 7.
Describe and sketch (on paper is fine) a computation form that you would like to create for your first class project. Consider all the methods that you know thus far and how they can be combined. Also, feel free to make it interactive or animated or both.
green something is growing on Manhattan street starting from B'way and Waverly pl.(ITP)