Problem 1. Write a program that allows the user to draw a stroke of up to 1000 points. Optionally, implement a feature that prevents the addition of points that are closer than 5 pixels from the last point added.
void drawProblem1(int spacing){
glColor3f(1,0,0);
glLineWidth(1);
glBegin(GL_LINE_STRIP);
for (int i = 1; i < numPoints; i++){
float deltaX = pointList[i-1].x - pointList[i].x;
float deltaY = pointList[i-1].y - pointList[i].y;
float len = sqrt(pow(deltaX,2) + pow(deltaY,2));
if (len < spacing){
pointList[i] = pointList[i-1];
}
glVertex2f(pointList[i].x, pointList[i].y);
}
glEnd();
}
Problem 2. Create a function that draws the stroke (from Problem 1) using the special wide-stroke method. The function should take as input the desired with of the stroke as a float.
Problem 3. Create a function that draws the stroke with a three-step stair-step pattern along it on just one side of the stroke.
void drawProblem3(int strokeWidth){
glColor3f(1,0,0);
glLineWidth(1);
glBegin(GL_LINE_STRIP);
for (int i = 1; i < numPoints - 1; i++){
Vec2d currentPoint = pointList[i];
Vec2d A = pointList[i-1];
Vec2d B = pointList[i+1];
Vec2d V = B - A;
V.normalize();
Vec2d Vp;
Vp.x = V.y * -1.0;
Vp.y = V.x;
Vec2d C = currentPoint + Vp*strokeWidth*2;
Vec2d D = C + V*strokeWidth;
Vec2d E = D - Vp*(strokeWidth-strokeWidth/3);
Vec2d F = E + V*strokeWidth;
Vec2d G = F - Vp*(strokeWidth-strokeWidth/3);
Vec2d H = G + V*strokeWidth;
Vec2d I = H - Vp*(strokeWidth-strokeWidth/3);
Problem 4. Create a function that the draws the stroke with a wave that runs perpendicular to the direction of the stroke. The wave should affect the path of the stroke, not its width. The function should take an amplitude and frequency as input
Problem 5. Create a function that the draws the stroke with a giant arrowhead at its tip. The arrowhead should be in alignment the last stroke segment. Optionally, draw a series of similar but smaller arrows along the length of the whole stroke.
void drawProblem5(){
float strokeWidth = 10;
glLineWidth(1);
glBegin(GL_LINES);
for (int i = 1; i < numPoints - 1; i++){
Vec2d currentPoint = pointList[i];
Vec2d A = pointList[i-1];
Vec2d B = pointList[i+1];
Vec2d V = B - A;
V.normalize();
Vec2d Vp;
Vp.x = V.y * -1.0;
Vp.y = V.x;
Vec2d C = currentPoint + Vp*strokeWidth - V*strokeWidth * 4;
Vec2d D = currentPoint - Vp*strokeWidth - V*strokeWidth * 4;
glColor3f(1,0,0);
glLineWidth(1);
glBegin(GL_POINTS);
for (int i = 1; i < numPoints - 1; i++){
Vec2d currentPoint = pointList[i];
Vec2d A = pointList[i-1];
Vec2d B = pointList[i+1];
Vec2d P = B - A;
P.normalize();
Vec2d N;
N.x = P.y * -1.0;
N.y = P.x;
for (int z = numPoints; z > 0; z--){
float angle = 2 * PI / numPoints * z;
float offset = 500 * d_sin(angle*2);
Vec2d C = pointList[z-1] + N * offset;
glVertex2f(C.x, C.y);
}
//glVertex2f(pointList[i].x, pointList[i].y);
}
glEnd();
}
Problem 7. Create a function that rotates a shape by a given angle. The function should take as input an array of points (Vec2d *), the number of points in the array (int), and an angle of rotation in degrees. You may want to calculate the center point and then rotate the points around the center, rather than about the window origin.
void drawProblem7(float angle){
glColor3f(1,0,0);
glLineWidth(1);
angle = mouseX;
Vec2d A = Vec2d(0,0);
Vec2d B = Vec2d(0, 100);
Vec2d C = Vec2d(100, 100);
Vec2d D = Vec2d(100, 0);