CompuForm Week 5 · posted by vaibhav bhawsar Oct 15, 04:01

Problem 1

void pen()
{	
		//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
		glBegin(GL_LINE_STRIP);
		glColor3f(c*255,c*100,c*50);		
		for(int i = 0 ; i < numberOfpoints ; i++)
		{
			Vec2d currentPoint = pointList[i];
			glVertex2f(currentPoint.x,currentPoint.y);
		}
		glEnd();
}

Problem 2

void pen(float s)
{
	float strokeWidth = s;
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glBegin(GL_TRIANGLE_STRIP);
	glColor4f(c*255,c*100,c*50,.6);		
	for(int i = 1 ; i < numberOfpoints-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; 
		Vec2d D =currentPoint-Vp * strokeWidth;
		glVertex2f(C.x,C.y);
		glVertex2f(D.x,D.y);
	 }
	glEnd();
}

Problem 3

void penStep(float s)
{
	float strokeWidth = 20;
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glBegin(GL_TRIANGLE_STRIP);
	glColor4f(c*255,c*100,c*50,.7);		
	int nSteps = 0;
	for(int i = 1 ; i < numberOfpoints-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;
		if(i%20==0)
		 {
			strokeWidth = strokeWidth + 20;
			nSteps+=1;
		 }
		if(nSteps==4)
		 {
			nSteps = 0;
			strokeWidth =10;
		 }
		Vec2d C =currentPoint + Vp * strokeWidth;
		Vec2d D =currentPoint-Vp * strokeWidth;
		glVertex2f(C.x,C.y);
		glVertex2f(D.x,D.y);
	 }
	glEnd();
}

Problem 4

void penWave(float s, float amplitude, float freq)
{
	float strokeWidth = 20;
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glBegin(GL_TRIANGLE_STRIP);
	glColor4f(c*255,c*100,c*50,.7);		
	int nSteps = 0;
	amplitude = 20;
	for(int i = 1 ; i < numberOfpoints-1 ; i++)		
	 {	
		float X = i;
		float Y = ( amplitude * d_sin(X * freq) ) + 25;
		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 * Y;
		glVertex2f(C.x,C.y);
		Vec2d D = currentPoint; // + Vp * (Y+5);
		glVertex2f(D.x,D.y);
	 }
	glEnd();
}

Problem 5

void penArrow(float s)
{
	float strokeWidth = s;
	Vec2d a; //arrow front
	Vec2d C; //perpendicular to stroke points
	Vec2d D; //perpendicular to stroke points	
	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glBegin(GL_TRIANGLE_STRIP);
	glColor4f(c*255,c*100,c*50,.6);		
	for(int i=1;i<numberOfpoints-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;
		
		C =currentPoint+Vp * strokeWidth; 
		D =currentPoint-Vp * strokeWidth;
		
		glVertex2f(C.x,C.y);
		glVertex2f(D.x,D.y);
		
		//normalize perpendicular to C and D to get arrow tip 'a'
		Vec2d aN = D - C;
		aN.normalize();
		Vec2d aTip;
		aTip.x = aN.y*-1.0;
		aTip.y = aN.x;
		a = currentPoint+(aTip*60);
	 }
	glEnd();
	
	//drawing the arrow
	glBegin(GL_TRIANGLES);
	glColor4f(c*0,c*255,c*255,0.3);		
	Vec2d arrowP = pointList[numberOfpoints];
	glVertex2f(C.x,C.y);
	glVertex2f(D.x,D.y);
	glVertex2f(a.x,a.y);
	glEnd();
}

Comment

Commenting is closed for this article.