CompuForm Week 3 · posted by vaibhav bhawsar Oct 15, 03:39

Problem 1

void drawCrest(Vec2d v, float wavelength, float amplitude)
{	
	glBegin(GL_LINE_STRIP);
	glColor3f( .8,.2,.4 );
	for (int i = 0 ; i < 360 ; i++)
	{
		float X = i;
		float Y = (amplitude * d_sin( X *  (360/wavelength) ));
		Y = fabs(Y);
		glVertex2f(X+v.x,Y+v.y);
	}
	glEnd();
}

Problem 3

void drawDaisy( int numPetals, float radius, float petalLength )
{
	float Amp = petalLength;
	int Frequency = numPetals;
	float phase = 0;
	glBegin(GL_LINE_LOOP);
	for (int i = 0 ; i <= 360 ; i++)
	{
		float X = i;
		float Y = ( Amp * d_sin(X * Frequency) ) + radius;
		float Angle = ( ( 2 * PI ) / 360) * i;
		float x = (cos(Angle) * Y);
		float y = (sin(Angle) * Y);
		glColor3f( .1,.2,.4 );
		glVertex2f( x + windowW/2 , y + windowH/2);
	}
	glEnd();	
}

Problem 4

void drawGear(Vec2d v, int nTeeth, float innerR, float outerR )
{
	glColor3f( 1,0,1 );
	glBegin(GL_LINE_STRIP);	
	for ( int i = 0 ; i <= 360 ; i++ )
	{
	int Z = 360 / nTeeth;
	int X = (i/Z);
	int Y = outerR*((X) % 4) + innerR;
	float Angle = ( ( 2 * PI ) / 360) * i;
	float x = (cos(Angle) * Y);
	float y = (sin(Angle) * Y);
	glVertex2f( x + v.x , y + v.y);	 
	}
	glEnd();
}

Problem 5/7
//DRAWBLOB//

float Phase = 0.0;
void drawBlob( int numPetals, float radius, float petalLength )
{
	float Amp = petalLength;
	int Frequency = numPetals;
	glBegin(GL_LINE_LOOP);
	float r = rand() % 3;	
	for (int i =0; i<=360; i++)
	{
		float X = i;
		float Y = ( Amp * d_sin( X * Frequency) ) + radius;
		Y = Y + Amp * d_sin ( (X) + Phase ) + r ;
		Y = Y + Amp * d_sin ( (X/radius * r) + Phase ) ;
		float Angle = ( ( 2 * PI ) / 360) * i;
		float x = (cos(Angle) * Y);
		float y = (sin(Angle) * Y);
		glColor3f( .8,.2,.4 );
		glVertex2f( x + windowW/2 , y + windowH/2);
	}
	Phase+=0.04;
	glEnd();	
}
//under display func//
		case ( 4 ) :
		//----------------DRAW bLoB---------------//
		drawBlob(60,100,15);
		drawBlob(6,100,15);
		for ( int i = 0 ; i<8;i++){
		drawBlob(7,50+(i*6),8);	
		}
		//-------------------------------//
		break;

Comment

Commenting is closed for this article.