Udder-Utter · posted by vaibhav bhawsar 138 days ago


New Interfaces For Musical ExpressionNIME

Udder-Utter is an instrument that utters syllabic sounds derived from the Devanāgarī alphabet, which is used to write Hindi and other Indo-Arayan languages. It’s playability is inspired by the gestures involved in milking a cow. The sounds that this instrument utters are intended to be a mix of discrete and continuous in nature and are rhythmic due to their syllabic/phonetic origins. I see the Udder as an instrument for constructing and rupturing meaning through its playability by using syllabic sounds to construct monosyllabic meanings and imagery to extract formal elements.

Playing the instrument primarily involves manipulating and generating phonetic sounds. In addition the instrument allows its player to control a visual system explained below.

Screenshots of the visual system

The screen component for the performance reacted to the instrument. For this I had to interface MAX/MSP to C++ via openFrameworks and OSC.
The visual idea was to extract colours out of images and simultaneously erase them in the process. Image pixels were used to read colours and then the colours were mapped onto a stroke that was modulated depending on sensor values from the instrument. The speed with which the image lost colours depended on how the instrument was played (fast/slow gestures) and on certain other parameters.

A short video from the ITP NIME performance

Notes on the Imagery: I was interested in playing with the expression “milking the cash cow” by literally having the instrument sap colours out of currencies (notes/bills). I selected a series of currencies from nations that celebrate their abundance of natural resources and manpower through use of illustrations. These illustrations are references to their “cash cow”. One sees patterns of representation through iconography- such as farmers, tractors, cash crops, chimneys, industrial sheds, mineral deposits, mines etc, all of which serve as mastheads of development for emerging economies. In the globalized landscape such countries see themselves as offshore providers of resources to larger and richer countries. In turn such emerging economies are in ways the cash cow for richer nations who often sift for foreign resources before they start to consume their own as an act of self-preservation or find it cheaper to do so in their neo-imperialistic spirit. It is this vicious underrepresented portrait of national interests vs vested interests that I wanted to express through this instrument and performance. To me it was important to represent the consumed and less the consumer.

Utterrr

CompForm Final · posted by vaibhav bhawsar 281 days ago

The screen component for the performance reacted to the instrument I built for the NIME class. For this I had to interface MAX/MSP to C++ via openFrameworks and OSC.
The visual idea was to extract colours out of images and simultaneously erase them in the process. Image pixels were used to read colours and then the colours were mapped onto a stroke that was modulated depending on sensor values from the instrument. The speed with which the image lost colours depended on how the instrument was played (fast/slow) and on certain other parameters.

udder in use:

Comment

CompForm Assignment 10 · posted by vaibhav bhawsar 281 days ago

Problem 1. Add the OpenGL lighting code to your project. This code may be placed in the init() function or in the displayFunc(), if you want to move or change the light.

void init ( GLvoid )
{
	glShadeModel( GL_SMOOTH );
	glClearColor( 0.1, 0.1, 0.1, 1.0 );
	glEnable ( GL_COLOR_MATERIAL );
	glEnable( GL_BLEND );
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	//turn on GL lighting
	glEnable(GL_LIGHTING);
	// turn on first light
	glEnable(GL_LIGHT0);
	//setup lighting params
	float ambientLight[4] = { 0, 0, 0, 1.0 };		//r,g,b,a //omni
	float diffuseLight[4] = { 1, 1, 1, 1.0 };		//r,g,b,a //color of the light bulb
	float specularLight[4] = { 0.8, 0.8, 0.8, 1.0 };	//r,g,b,a //the shiny part of the object
	float lightPosition[4] = { 500, 500, 1000, 1.0 };	//x,y,z,other //pos of the light
	//which light, property, propoertyvalue
	glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
	glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight);
	glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);
	//enable glColor3f to affect the material color
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);	
}

Comment

CompForm Assignment 9 · posted by vaibhav bhawsar 281 days ago

Problem 1: Add a function called drawWirefame to the Mesh class. This function should draw the Mesh as a wireframe.

void Mesh::drawWireFrame()
{
	for ( int x=0 ; x < gridW-1 ; x++ )
	{
		for(int z =0 ; z < gridH-1 ; z++ )
		{
			//passing an array of three which 
                        //out vec3d is into this particular opengl method
			//glVertext3fv( (float*) &grid[i][j]);
                        //--------
			Vec3d A = grid[x][z];
			Vec3d B = grid[x][z+1];
			Vec3d C = grid[x+1][z+1];
			glBegin(GL_LINE_LOOP);
			glVertex3f( A.x , A.y , A.z );
			glVertex3f( B.x , B.y , B.z );
			glVertex3f( C.x , C.y , C.z );
			glEnd();
                        //--------
			A = grid[x][z];
			B = grid[x+1][z+1];
			C = grid[x+1][z];
			glBegin(GL_LINE_LOOP);
			glVertex3f( A.x , A.y , A.z );
			glVertex3f( B.x , B.y , B.z );
			glVertex3f( C.x , C.y , C.z );
			glEnd();		
		}
	}		
}

Problem 2:Add a function called drawShadedSolid to the Mesh class. This function should draw the Mesh as a solid form with shading.

void Mesh::drawShadedSolid()
{
	for ( int x=0 ; x < gridW-1 ; x++ )
	{
		for ( int z=0 ; z < gridH-1 ; z++ )
		{
			Vec3d A = grid[x][z];
			Vec3d B = grid[x][z+1];
			Vec3d C = grid[x+1][z+1];
			fillShadedTriangle(A,B,C);
			
			A = grid[x][z];
			B = grid[x+1][z+1];
			C = grid[x+1][z];
			fillShadedTriangle(A,B,C);
		}
	}
}
void Mesh :: fillShadedTriangle(Vec3d A, Vec3d B, Vec3d C)
{
	float shading;
	//define vectors AB and AC
	Vec3d AB = B-A;
	Vec3d AC = C-A;
	//and compute the cross product between them
	//this is perpendicular to AB and AC
	Vec3d N = AB.cross(AC);
	//normalize the cross product
	N.normalize();
	//copy the light vector and norm it
	Vec3d L;
	L = light;
	L.normalize();
	//shading is the dot product, Light (L) is projected onto N
	shading = L.dot(N);
	if(shading <= 0) 
	{
		shading = 0.0;	
	}
	//compose the final tone of color
	glColor4f(shading*Red,shading*Green,shading*Blue, Alpha);
	glPushMatrix();
	glBegin(GL_TRIANGLES);
	glVertex3f(A.x,A.y,A.z);
	glVertex3f(B.x,B.y,B.z);
	glVertex3f(C.x,C.y,C.z);
	glEnd();
	glPopMatrix();
}

Problem 3:Add a function to the Mesh class called makeExtrusion. The function should take as inputs an array of points that define the extrusion shape, the number of points in the shape, and the depth of the extrusion. In order for this to work correctly, the number of points in the extrusion shape should equal either the width or height of the mesh.

void Mesh::makeExtrusion(Vec3d* shape, int depth)
{
	for ( int D =0 ; D < gridW ; D++ ) //for each depth
	{
		for ( int A = 0 ; A < gridH ; A++ ) //draw 
		{
			float x = shape[A].x;
			float z = depth / (gridH-1) * A; // D * depth; //this is what i was doing
			float y = shape[A].y;
			grid[D][A] = Vec3d(x,y,z);
		}
	}
}

Problem 4. Add a function to the Mesh class called makeRevolution. The function should take as inputs an array of points that define the revolution profile, and the number of points in the profile. In order for this to work correctly, the number of points in the profile should equal either the width or height of the mesh.

void Mesh::makeRevolutionProfile(Vec3d* profile)
{
	//should have a center vec3d so 
        //that you can move this thing around
	float radius = 0;
	for (int D =0 ; D < gridH ; D++) //number of rings
	{
		radius = profile[D].y; //set the x of the profile as the radius
			for ( int A = 0 ; A < gridW ; A++ )
			{
				float ang = A / (float) (gridH-1) * 2 * PI; //npoints-1 so that compensate 
				float x = radius * cos (ang);
				float y = profile[D].x;
				float z = radius * sin (ang);
				grid[D][A] = Vec3d(x,y,z);
			}
	}
}

Problem 5. Add a function to the Mesh class called makeSphere. The function should take as input the radius of the sphere. The latitudinal and longitudinal divisions of the sphere will depend on the width and height of the mesh.

//--called in the init()
	int sPoints = 60;
	sphereMesh = new Mesh(sPoints,sPoints);
	sphereMesh2 = new Mesh(sPoints,sPoints);
	Vec3d* circle = generateSemiCircle(100,sPoints);
	sphereMesh->setColor(1,.2,.2,.5);
	sphereMesh->makeRevolutionProfile(circle);
	sphereMesh2->setColor(.2,.2,.2,.8);	
	sphereMesh2->makeRevolutionProfile(circle);
//-----------helper func to generate a semicircle of points-----------
Vec3d* generateSemiCircle(float r, int nPoints)
{	
	Vec3d* p = new Vec3d[nPoints];
	for ( int i=0 ; i < nPoints ; i++ )
	{
		float ang = PI / (nPoints-1) * i;
		float x = r * cos(ang) ;
		float y = r * sin(ang) ;
		p[i] = Vec3d(x,y,0);
	}
	return p;
}
//----------called within displayFunc-----------
sphereMesh->drawSolid();

Comment

CompuForm Assigment 8: Intro to Lighting/Shading · posted by vaibhav bhawsar 325 days ago

Common Function to Generate Mesh

void generateMesh(int meshW, int meshH)
{
	//gen a simple mesh of a certain width and height
	for (int W=0; W<meshW ; W++)
	{
		for (int H=0; H<meshH ; H++)
		{
			float x = W - (meshW/2);
			float y = 0;
			float z = H - (meshH/2);
			mesh[W][H] = Vec3d(x,y,z);
		}
	}
}

Common Function to Shade Mesh (unit triangle)

void shadedTriangle(Vec3d A, Vec3d B, Vec3d C, float Rf, float Gf, float Bf, float Af)
{
	float shading;
	//define vectors AB and AC
	Vec3d AB = B-A;
	Vec3d AC = C-A;
	//and compute the cross product between them
	//this is perpendicular to AB and AC
	Vec3d N = AB.cross(AC);
	//normalize the cross product
	N.normalize();
	//create the light vector and norm it
	Vec3d L(mouseX,mouseY,0);
	L.normalize();
	//shading is the dot product, Light (L) is projected onto N
	shading = L.dot(N);
	if(shading <= 0) shading = 0;
	//compose the final tone of color
	glColor4f(Rf*shading,Gf*shading,Bf*shading, Af);
	glPushMatrix();
	glBegin(GL_TRIANGLES);
	glVertex3f(A.x,A.y,A.z);
	glVertex3f(B.x,B.y,B.z);
	glVertex3f(C.x,C.y,C.z);
	glEnd();
	glPopMatrix();
}

Problem 1: Create a 30 × 30 mesh using a two-dimensional array of Vec3D’s. Then create a function that draws your mesh as a wireframe. (Be sure to use “const int” variables represent the width and height of your mesh, instead of hard-coding it always to be 30 × 30.)

void drawMesh()
{
	//draw the mesh
	//draw along Height (depth z) while incrementing Width
	for (int W=0; W<meshW ; W++)
	{
		glBegin(GL_LINE_STRIP);
		for (int H=0; H<meshH ; H++)
		{
			Vec3d pt = mesh[W][H];
			glVertex3f(pt.x,pt.y,pt.z);
		}
		glEnd();
	}
	//draw along WIDTH while incrementing HEIGHT (depth z)	
	for (int H=0; H<meshH ; H++)	
	{
		glBegin(GL_LINE_STRIP);
		for (int W=0; W<meshW ; W++)
		{
			Vec3d pt = mesh[W][H]; //draw along W
			glVertex3f(pt.x,pt.y,pt.z);
		}
		glEnd();
	}
}

Problem 2: Create a function that draws your mesh a solid surface and sets the color of each face according to the simple lighting model discussed in class.

void drawFillMesh()
{
	for (int z=0; z < meshW-1 ; z++)
	{
		for (int x=0; x < meshH-1 ; x++)
		{
			Vec3d A = mesh[x][z];
			Vec3d B = mesh[x][z+1];
			Vec3d C = mesh[x+1][z+1];
			shadedTriangle(A,B,C,.5,.01,1,.8);
			A = mesh[x][z];
			B = mesh[x+1][z+1];
			C = mesh[x+1][z];
			shadedTriangle(A,B,C,.5,.01,1,.8);
		}
	}
}

Problem 3: Create a function that makes a mountain out of your mesh.
generateMountain() is called instead of generateMesh() after which drawFillMesh() is called.

void generateMountain()
{
	//gen a simple mesh of a certain width and height
	for (int W=0; W<meshW ; W++)
	{
		for (int H=0; H<meshH ; H++)
		{
			float x = W - (meshW/2);
			float z = H - (meshH/2);
			float y = 5*(cos(x/5)  + cos (z/5));
			mesh[W][H] = Vec3d(x,y,z);
		}
	}
}

Problem 4: Create a function that produces waves in one direction (along x) in your mesh.

void generateXWave()
{
	//gen a simple mesh of a certain width and height
	float amplitude = 5.0;
	float wavelength = 10.0;
	
	for (int W=0; W<meshW ; W++)
	{
		for (int H=0; H<meshH ; H++)
		{
			float x = W - (meshW/2);
			float z = H - (meshH/2);
			float y = ( amplitude * d_cos( x *  (180/wavelength)) );
			y = fabs(y);
			mesh[W][H] = Vec3d(x,y,z);
		}
	}
}

Problem 5: Create a function that produces waves in two directions (along x and z ) in your mesh.

void generateXYWave()
{
	//gen a simple mesh of a certain width and height	
	for (int W=0; W<meshW ; W++)
	{
		for (int H=0; H<meshH ; H++)
		{
			float x = W - (meshW/2);
			float z = H - (meshH/2);
			float y = 2*(cos(x/2)  + cos (z/5)) ;
			y = fabs(y);
			mesh[W][H] = Vec3d(x,y,z);
		}
	}
}

Problem 6: Create a function that adds random variation to your mesh. Then using a two-dimensional smoothing function, smooth out the mesh. The smoothing function for each point should take into acount the four points directly connected to it. It may also include the other four points that are diagonally related to it. The inputs to this function should be the height of the random variation, and the level of smoothing.

void generateRandomMesh(int meshW, int meshH)
{
	//gen a mesh of a certain width and random height using the values stored in randomPoints[] (Y)
	for ( int W=0 ; W < meshW ; W++ )
	{
		for ( int H=0 ; H < meshH ; H++ )
		{
			float x = W - (meshW/2);
			int phase = ((int)(p*0.8)-H) % meshW;
			float y = -4;
			
			if(W>1 && H>1 && W<meshW-1 && H<meshH-1)
			{
				y = randomPoints[W][phase];	
			}
			
			//float y = randomPoints[W][H];
			float z = H - (meshH/2);
			mesh[W][H] = Vec3d(x,y,z);
		}
	}
	
	//SMOOTH THE MESH
	if(meshSmoothing)
	{
		for ( int sW=1 ; sW < meshW-1 ; sW++ )
		{
			for ( int sH=1 ; sH < meshH-1 ; sH++ )
			{
				Vec3d currentP = mesh[sW][sH];
				Vec3d TopP = mesh[sW][sH-1];
				Vec3d BottomP = mesh[sW][sH+1];
				Vec3d LeftP = mesh[sW-1][sH];			
				Vec3d RightP = mesh[sW+1][sH];
				
				Vec3d TopRightP = mesh[sW+1][sH-1];
				Vec3d TopLeftP = mesh[sW-1][sH-1];
				Vec3d BottomRightP = mesh[sW+1][sH+1];
				Vec3d BottomLeftP = mesh[sW-1][sH+1];
				
				Vec3d smoothP = currentP*0.2 + 
				TopP *0.1 + 
				BottomP * 0.1 + 
				LeftP * 0.1 + 
				RightP * 0.1 +
				TopRightP * 0.1 + 
				TopLeftP * 0.1 + 
				BottomRightP * 0.1 + 
				BottomLeftP * 0.1 ;
				
				mesh[sW][sH] = smoothP;
			}
		}
	} 
	
}

Problem 7 ?

CompuForm Assigment 7: 3D · posted by vaibhav bhawsar 340 days ago

cylinder wireframe extrude a 2d set of points (a wave in this case)

Problem 1: Create a function called drawWireframeCylinder that takes as input a radius (float), a height (float) and a number of steps (int). The function should draw a series of circles stacked vertically as specified. Draw vertical lines between the circles to complete wireframe effect.

void cylinder(float radius, float height, int nSteps)
{
	int nPoints = 30;
	Vec3d aShape[nSteps][nPoints];
	
	glPushMatrix();
	glRotatef(mouseY,1,0,0);
	
	color(255,0,255,255);
	for (int D =0 ; D < nSteps ; D++) //number of rings
	{
		glBegin(GL_LINE_LOOP);//draw each ring
		for ( int A = 0 ; A < nPoints ; A++ )
		{
			float ang = A / (float) nPoints * 2 * PI;
			float x = radius * cos (ang);
			float y = D * (height/nSteps) - height/2;
			float z = radius * sin (ang);
			glVertex3f(x,y,z);
			aShape[D][A] = Vec3d(x,y,z);
		}
		glEnd();
	}
	
	color(0,0,255,255);
	for (int A =0 ; A < nPoints ; A++) //iterate lat, X
	{
		glBegin(GL_LINE_LOOP); //draw each ring iterate long, Y
		for ( int D = 0 ; D < nSteps ; D++ )
		{
			Vec3d a = aShape[D][A];
			glVertex3f(a.x,a.y,a.z);
		}
		glEnd();
	}
	glPopMatrix();	
}

Problem 2: Create a function called drawWireframeExtrusion that takes as input an array of points (Vec2d*), the number of points (int), a height (float) and a number of steps (int). The function should draw a wireframe extrusion of the two-dimensional form that is passed in.

//globals 
//pixels
int wavePLength = 720; 
Vec2d waveP [720];
void drawCrest(Vec2d v, float wavelength, float amplitude)
{	
	
	glBegin(GL_LINE_STRIP);
	glColor3f( .8,.2,.4 );
	for (int i =0; i<wavePLength; i++)
	{
		float X = i;
		float Y = ( amplitude * d_sin( X *  (360/wavelength)) );
		Y = fabs(Y);
		glVertex2f(X+v.x,Y+v.y);
		Vec2d p (X+v.x,Y+v.y);
		waveP[i] = p;
	}
	glEnd();
}
void extrude (int nSteps,int height)
{
	drawCrest(Vec2d(-200,0),200,50);
	glPushMatrix();
	glRotatef(mouseY,1,0,0);
	color(255,255,0,255);
	for (int D =0 ; D < nSteps ; D++) //number of rings
	{
		glBegin(GL_LINE_STRIP); //draw each ring
		for ( int A = 0 ; A < wavePLength ; A++ )
		{
			float x = waveP[A].x;
			float y = D * (height/nSteps) - height/2;
			float z = waveP[A].y;
			glVertex3f(x,y,z);
			//aShape[D][A] = Vec3d(x,y,z);
		}
		glEnd();
	}
	glPopMatrix();
}

Problem 3. Create a function called drawWireframeRevolution that takes as input an array of points (Vec2d) and the number of points (int). The function should uses the array of points as a revolution profile. To do this, draw a circle for each point in the array where the circle’s radius is equal to the point’s X component, and the the circle’s vertical height is equal to the circle’s Y value. Complete the wireframe by drawing the vertical lines.

void drawWireframeRevolution()
{
	//generate a vertical bell curve
	int length = meshH;
	Vec2d p[length];
	glLineWidth(4);
	glBegin(GL_LINE_STRIP);
	glColor4f( .5,.5,.5,.5 );
	for (int i = 0 ; i < length ; i++)
	{
		float Y = i;
		float amp = 20;
		float n = Y/length;
		float falloff = pow ( 5.0, -1.0 * n * n );
		float X = amp * d_sin( n * 360) * falloff;
		glVertex2f(X,Y);
		Vec2d pt(X,Y);
		p[i] = pt;
	}
	glEnd();
	
	int nPoints = meshW;
	int height = length;
	int radius = 0;
	
	glPushMatrix();
	//glRotatef(mouseY,1,0,0);
	
	color(255,0,255,255);
	glLineWidth(1);
	for (int D =0 ; D < height ; D++) //number of rings
	{
		radius = p[D].x;
		glBegin(GL_LINE_LOOP);//draw each ring
		for ( int A = 0 ; A < nPoints ; A++ )
		{
			float ang = A / (float) nPoints * 2 * PI;
			float x = radius * cos (ang);
			float y = p[D].y;
			float z = radius * sin (ang);
			//glVertex3f(x,y,z);
			mesh[D][A] = Vec3d(x,y,z);
		}
		glEnd();
		
	}
	color(0,0,255,255);
	for (int A =0 ; A < nPoints ; A++) //iterate lat, X
	{
		glBegin(GL_LINE_STRIP);//draw each ring iterate long, Y
		for ( int D = 0 ; D < height; D++ )
		{
			Vec3d a = mesh[D][A];
			//glVertex3f(a.x,a.y,a.z);
		}
		glEnd();
	}
	glPopMatrix();
	
	drawWarpedFillMesh();
}
void drawWarpedFillMesh()
{
	for (int z=0; z < meshH-1; z++)
	{
		for (int x=0; x < meshW-1; x++)
		{
			Vec3d A = mesh[x][z];
			Vec3d B = mesh[x+1][z];
			Vec3d C = mesh[x+1][z+1];
			color(200,200,200,200);
			//fillTriangle(A,B,C);
			fillShadedTriangle(A,B,C,.1,.01,1,.8);
			
			A = mesh[x][z];
			B = mesh[x+1][z+1];
			C = mesh[x][z+1];
			color(255,255,255,235);			
			//fillTriangle(A,B,C);
			fillShadedTriangle(A,B,C,.1,.01,1,.8);
		}
	}
	for (int y=0; y < meshW-1; y++)
	{
		Vec3d A = mesh[y+1][0];
		Vec3d B = mesh[y][0];
		Vec3d C = mesh[y+1][meshH-1];
		//color(255,0,0,200);
		//fillTriangle(A,B,C);
		fillShadedTriangle(A,B,C,.1,.01,1,.8);
		
		A = mesh[y][0];
		B = mesh[y][meshH-1];
		C = mesh[y+1][meshH-1];
		//color(0,255,0,235);			
		//fillTriangle(A,B,C);
		fillShadedTriangle(A,B,C,.1,.01,1,.8);
	}
}

Comment

CompuForm Assigment 6: smoothing · posted by vaibhav bhawsar 353 days ago

Problem 1 – Smoothing

void smoothPoints(Vec2d line[], int nPoints)
{	
	for( int i = 1 ; i < nPoints-1; i++ )
	 {
		Vec2d p = line[i];//current point to smooth
		Vec2d prev; //previous point
		Vec2d next; //next point		
		if(i!=0)
			prev = line[i-1];
		else
			prev = line[0];
		if(i!=nPoints)
			next = line[i+1];
		else
			next = line[nPoints];
		//each multiplied by a smooth value- should add to 1
		Vec2d r  = prev*0.20 + p*.60 + next*0.20; 
		pointList[i] = r;
	 }
}

Problem 2 – Distortion

void bezierDistortedShape(Vec2d pos, int radius)
{
	int numberOfPoints = 90;
	int r = radius;
	Vec2d distortOrigin( mouseX , mouseY );
	Vec2d p[numberOfPoints];
	for(int i = 0; i<numberOfPoints; i++)
	 {
		float angle = 2 * PI / numberOfPoints * i;
		float x = sin(angle) * r;
		float y = cos(angle) * r;
		Vec2d tp(x,y);
		Vec2d fp = tp+pos;
		p[i] = fp;
	}
	//draw the shape
	glBegin(GL_POLYGON);
	glColor3f(.9,.1,.4);
	for(int i = 0; i<numberOfPoints ; i++)
	 {
		Vec2d point	= p[i];
		Vec2d V = distortOrigin - point; //vector between target point and distort Origin
		float length = V.length();
		V.normalize();
		float amp = 50;
		float radius = 50;
		
		//draw the star shape
		//if(i % 1)
		length = length / radius;	
		//else length = length / (radius/2);	 
		float mag = amp * ( 1 / length );
		
		Vec2d dPoint = point + (V * mag);
		glVertex2f( dPoint.x , dPoint.y );
	 }
	glEnd();
}

Problem 3 – intersections

Vec2d newshape[100];
int shapeCount=0;
int s1 = 0;
int s2 = 0; // numberofpoints at a the moment of intersection
void intersectShapes()
{
	pen();
	//currentpoint p0a
	//prevpoint p0b
	//numpoint and numpoint-1
	//i and i+1
	for( int i = 0 ; i < numberOfpoints-2 ; i++ )
	 {
		Vec2d P1a = pointList[numberOfpoints-1]; //currentpoint
		Vec2d P1b = pointList[numberOfpoints-2]; //prevpoint
		Vec2d P0a = pointList[i]; // point currently on
		Vec2d P0b = pointList[i+1]; // point previous to the one currently on
		if( checkIntersectLines(P0a, P0b, P1a, P1b) )
		 {
			printf("intersect \n");
			glColor3f(0,0.75,0);
			newshape[shapeCount] = P1a;
			shapeCount++;
			s1 = i+1;
			s2 = numberOfpoints;
			//printf("s1 %d, s2 %d \n", s1,s2);
			glRectf(P1a.x-4,P1b.y-4,P1a.x+4,P1b.y+4);
		 }
	 }
	
	//draw the small rects
	for (int i =0 ; i < shapeCount ; i++ )
	 {
		Vec2d n = newshape[i];
		glRectf(n.x-4,n.y-4,n.x+4,n.y+4);
	 }
	
	//draw the shape
	glBegin(GL_POLYGON);
	glColor4f(0,0.75,0,.5);
	for (int i = s1 ; i < s2 ; i++ )
	 {
		Vec2d p = pointList[i];
		glVertex2f(p.x,p.y);
	 }
	glEnd();
}

checkIntersectLines function

bool checkIntersectLines(Vec2d P0a, Vec2d P0b, Vec2d P1a, Vec2d P1b)
{
	float M0 = ( P0b.y - P0a.y ) / ( P0b.x - P0a.x ); //slope0 = dy/dx
	float M1 = ( P1b.y - P1a.y ) / ( P1b.x - P1a.x ); //slope1 = dy/dx
	float X = P1a.y - P0a.y - P1a.x * M1 + P0a.x * M0 ;
	X /= ( M0 - M1 );
	
	float Y = P0a.y + ( X - P0a.x ) * M0;
	
	//to check if intersection is within line segment bounds
	float left0 = min(P0a.x, P0b.x);
	float right0 = max(P0a.x, P0b.x);
	float left1 = min(P1a.x, P1b.x);	
	float right1 = max(P1a.x, P1b.x);
	
	//set colour to green if line segment intersect
	if( X > left0 && X < right0	&&	X > left1 && X < right1)
	 {
		return true;	
	 }
	else {
		return false;
	}
}

CompuForm Project 1 (Midterm) · posted by vaibhav bhawsar 357 days ago

A Radiolaria inspired form generator. Some of the most inspiring Radiolaria studies I came across were made by Ernst Haeckel who was a german biologist and artist.
To me the mineral skeletons of radiolaria are interesting formal structures that I can attempt to generate using what we have thus far covered in class. These skeletons have a very prominent symmetry and periodic form. My explorations will cover some of these concepts/techniques for generating computational forms-

  • periodic functions – generating unit shapes
  • bezier curves – expressing the periodic functions using bezier curves to form the skeleton units
  • operating on line segments with custom strokes
  • symmetrical – rotating the skeleton units to construct shapes

Midterm Sketches:

CompuForm Week 5 · posted by vaibhav bhawsar 359 days ago

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

CompuForm Week 4 · posted by vaibhav bhawsar 359 days ago

Problem 1

Vec2d mousepos;
Vec2d prevpos;
void mouseSteps ( int n )
{
	//set under glut callback for mousereleased
	if(mouseReleased)
	{
		prevpos = mousepos;
		mousepos.x = mouseX;
		mousepos.y = mouseY;
		mouseReleased = false;
	}	
	int nPoints = n+1;
	float dP = 1.0 / nPoints;
	Vec2d A = mousepos;
	Vec2d B = prevpos;
	glBegin( GL_LINE_STRIP);
	for (float p = 0 ; p <= 1.001 ; p+=dP )
	{
	Vec2d C =  A * ( 1.0 - p ) + B * p;
	float Y = fmod(p,.1000f);
	if(Y){
	glColor3f(1,1,0);
	}else{
	glColor3f(1,1,1);
	}
	drawCircle(C,4,8);
	}
}

Problem 2

void blendShape(int numberOfSteps)
{
	int nPoints = 20;
	Vec2d shapeA[nPoints];
	Vec2d shapeB[nPoints];
	int rA = 100;
	int y = windowH/2;
	Vec2d posA(150,y);
	int rB = 50;
	Vec2d posB(1300,y);
	
	//generate shapeA
	for(int i = 0 ; i < nPoints ; i++){
		float angle = 2*PI / nPoints * i;
		float x = cos(angle) * rA;
		float y = sin(angle) * rA;
		Vec2d p(x,y);
		Vec2d c = p + posA;
		shapeA[i] = c;
	}
	
	//generate shapeB	STAR
	for(int i = 0 ; i < nPoints ; i++){
		float angle = 2*PI / nPoints * i;
		Vec2d p;
		if ( i % 2 ) {
			p.x = cos(angle) * (rB);
			p.y = sin(angle) * (rB);
		} else {
			p.x = cos(angle) * (rB+20);
			p.y = sin(angle) * (rB+20);
		}
		Vec2d c = p + posB;
		shapeB[i] = c;
	}
	
	//generate blend shape
	for(int i = 0 ; i < nPoints ; i++ ) 
	{
		Vec2d A = shapeA[i];
		Vec2d B = shapeB[i];
		float dP = 1.0 / (numberOfSteps+1);
		
		glPointSize( 2 );
		glBegin( GL_POINTS);
		glColor3f( .8,1,1 );			
		for ( float p = 0 ; p <= 1.001 ; p+=dP )
		{
			if(i%2) glColor3f( .8,1,1 );
			else glColor3f( c*256,c*64,0 );
			Vec2d C =  A * ( 1.0 - p ) + B * p;
			glVertex2f(C.x,C.y);
		}
		glEnd();
	}
	for(int i = 0; i < nPoints ; i++ ) 
	{
		Vec2d a = shapeA[i];
		glBegin(GL_LINE_LOOP);
		glColor3f(0,0,0);
		glVertex2f(a.x,a.y);
	}
	glEnd();
	for(int i = 0 ; i < nPoints ; i++ ) 
	{
		Vec2d b = shapeB[i];
		glColor3f(0,0,0);
		glBegin(GL_LINE_LOOP);
		glColor3f(0,0,0);
		glVertex2f(b.x,b.y);
	}
	glEnd();
}

Problem 3

void bezier(Vec2d A, Vec2d B, Vec2d c1, Vec2d c2)
{
	int nPoints = 122;
	float dP = 1.0 / nPoints;
	for ( float p = 0; p < 1.001 ; p+=dP )
	{
		float b = 1.0 - p;
		Vec2d v = A*b*b*b + c1*3*b*b*p + c2*3*b*p*p + B*p*p*p;
		glBegin(GL_LINE_STRIP);
		glColor3f(1,0,1);
		glVertex2f(v.x,v.y);
	}
	glEnd();
	bool drawHandles = true;
	if (drawHandles)
	{
	glColor4f(1,0,1,.5);
	glRectf( A.x-5, A.y-5, A.x + 5, A.y + 5 );
	glRectf( B.x-5, B.y-5, B.x + 5, B.y + 5 );	
	glColor4f(1,1,0,.5);
	glRectf( c1.x-5, c1.y-5, c1.x + 5, c1.y + 5 );
	glRectf( c2.x-5, c2.y-5, c2.x + 5, c2.y + 5 );
	}
}

Problem 4

//generating shapes out of beziers//
bool generateArray = true;
Vec2d* bShape1;
Vec2d* bShape2;
void bezierShape()
{
	int numberOfPoints = 90;
	
	//this is one time only
	if(generateArray)
	{
		bShape1 = generateDaisy(10,50,10,numberOfPoints);
		bShape2 = generateDaisy(10,200,50,numberOfPoints);
		generateArray = false;
		printf("arrayGenerated");	
	}
	//draw the beziers
	for(int i = 0; i<numberOfPoints ; i++)
	{
		Vec2d pos(windowW/2,windowH/2);
		Vec2d a = bShape1[i] + pos;
		Vec2d b = bShape2[i] + pos;
		bezier(a,b,Vec2d(mouseX,mouseY),Vec2d(mouseX,mouseY));
	}
}

Comment

CompuForm Week 3 · posted by vaibhav bhawsar 359 days ago

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

NIME - Performance note · posted by vaibhav bhawsar 374 days ago

Messa Di Voce is a collaboration between sound poet Japp Blonk and Joan La Barbara , media artists/musicians Golan Levin and Zach Lieberman .

In this performance a number of sound poems are supported by real-time visualizations.

The performance touches on themes of abstract communication, synaesthetic relationships, cartoon language, and writing and scoring systems, within the context of a sophisticated, playful, and virtuosic audiovisual narrative.

The performance blends together the spontaneity of the sound poems with the visuals generated by the program. Because this performance is playful, the artist and the screen are seamless and its interesting to observe the interplay between the two.
In some ways the activity on screen leverages/augments the sound poems (considering its an expert technique of the artist- in this case Jaap Blonk).
There is also something magical about pure syllables and their lucid visual representations.
Overall the shape of sound (phonesthesia) is an interesting idea that this performance/project successfully explores.

Comment

Comform Assignment 2 - Problem 6 · posted by vaibhav bhawsar 382 days ago

Problem 2 Touching Ovals Necklace Clock

Problem 6. Create a function called drawClock that takes as arguments an hour (float), a minute (float) and a number of seconds (float), and draws an analog clock. Feel free to add a pendulum or any other fancy clock accoutrements.

void drawClock( float hours, float min, float sec)
{
	float HOURANGLE = 30;//for every hour the hand moves 360/12//
	float MINANGLE = 6; //for every minute the hand moves 360/60//
	float SECANGLE = 6; //for every second the hand moves 360/60//
	float hour = hours;
	float minutes = min;
	float seconds = sec;	
	float hourA = ((12-hour)*HOURANGLE)+90; //add 90 to correct rotation
	float minutesA = ((60-minutes)*MINANGLE)+90;
	float secondsA = ((60-seconds)*SECANGLE)+90;	
	Vec2d center(windowW/2,windowW/2);
	float clockRadius = 100;
	drawCircle(center,clockRadius,30);
        // //
	glColor3f(1,0,0);
	glLineWidth(3);
	glPushMatrix();
	glTranslatef(center.x,center.y,0);
	glRotatef(hourA,0,0,1);
	glBegin(GL_LINE_LOOP);
	glVertex2f(0,0);
	glVertex2f(30,0);
	glEnd();
	glPopMatrix();
        // //
	glColor3f(1,1,0);	
	glLineWidth(2);
	glPushMatrix();
	glTranslatef(center.x,center.y,0);
	glRotatef(minutesA,0,0,1);
	glBegin(GL_LINE_LOOP);
	glVertex2f(0,0);
	glVertex2f(50,0);
	glEnd();
	glPopMatrix();
	// //
	glColor3f(1,0,1);	
	glLineWidth(1);	
	glPushMatrix();
	glTranslatef(center.x,center.y,0);
	glRotatef(secondsA,0,0,1);
	glBegin(GL_LINE_LOOP);
	glVertex2f(0,0);
	glVertex2f(70,0);
	glEnd();
	glPopMatrix();
} 

CompForm Assignment 2 - Problem 5 · posted by vaibhav bhawsar 382 days ago

Problem 2 Touching Ovals Necklace Clock

Problem 5. Create a function called drawNecklace that draws a pearl necklace. Feel free to shade the pearls or make them sparkle in the light of the moving mouse.

void drawNecklace ( Vec2d c, float hr, float vr, int numberOfPoints )
{
	for(int i = 0; i < numberOfPoints; i++)
	{
		float angle = 2*PI / numberOfPoints * i;
		float x = sin(angle) * hr;
		float y = cos(angle) * vr;
		Vec2d p(x,y);
		p = p+c;
		drawCircle(p,20,20);
	}
}

Comment

CompForm Assignment 2 - Problem 4 · posted by vaibhav bhawsar 382 days ago

Problem 2 Touching Ovals Necklace Clock

Problem 4. Create a function called drawStar that takes as arguments an inner radius (float), an outer radius (float), a number of points (int), and a center point (Vec2d) and draws a star as specified. Demonstrate that this function works by drawing 100 stars with a varying number of points placed randomly about the screen. Feel free to change the background color for a more dramatic effect.

void drawStar(Vec2d c)
{
	int innerRadius		=	70;
	int outerRadius		=	90;
	int numberOfPoints	=	30;
	Vec2d center(c.x,c.y);
	Vec2d p;
	glBegin(GL_TRIANGLE_FAN);
	glVertex2f(center.x,center.y);
	for(int i=0; i < numberOfPoints+1 ; i++)
	{
		float angle = 2 * PI / numberOfPoints * i;
		if ( i % 2 ) {
			p.x = cos(angle) * innerRadius;
			p.y = sin(angle) * innerRadius;
		} else {
			p.x = cos(angle) * outerRadius;
			p.y = sin(angle) * outerRadius;
		}
		p = center + p;
		glVertex2f(p.x,p.y);
	}
	glEnd();
}
void drawStarField()
{
	for( int i=0 ; i < 10 ; i++ )
	{
		int w = rand() % windowW; //printf("%d \n",w);
		int h = rand() % windowH; //printf("%d \n",w);
		drawStar(Vec2d(w,h));
	}
}

CompForm Assignment 2 - Problem 3 · posted by vaibhav bhawsar 382 days ago

Problem 2 Touching Ovals Necklace Clock

Problem 3. Create a function called drawOval that takes as arguments a horizontal radius (float), a vertical radius, a number of points (int) and a center point (Vec2d) and draws an oval as specified. Demonstrate that this function works by drawing 10 ovals in a row, each with an increasing horizontal radius (10, 20, 30…) and decreasing vertical radius (100, 90, 80…).

void drawOval ( Vec2d c, float hr, float vr, int numberOfPoints ) {
	glBegin(GL_POLYGON);
	glColor3f(0,0,0);
	for(int i = 0; i < numberOfPoints; i++){
		float angle = 2*PI / numberOfPoints * i;
		float x = sin(angle) * hr;
		float y = cos(angle) * vr;
		Vec2d p(x,y);
		p = p+c;
		glVertex2f(p.x,p.y);
	}
	glEnd();
}
void drawTouchingOvals()
{
	int numberOfOvals = 10;
	int nPoints = 30;
	Vec2d origin(0,400);
	for(int i=1; i<=numberOfOvals; i++){
		float hr = i*10;	//hor radius
		float vr = 110-hr;	//ver radius	
		//printf("horizontal %f , vertical %f \n",hr,vr);
		float dx = (hr*2)-10;//offset
		Vec2d shift(dx,0);
		origin = origin+shift;
		drawOval(origin,hr,vr,nPoints);
	}
}

CompForm Assignment 2 - Problem 2 · posted by vaibhav bhawsar 382 days ago

Problem 2 Touching Ovals Necklace Clock

Problem 2. Create a function called drawCircle that takes as arguments a radius (float), a number of points (int) and a center point (Vec2d) and draws a circle as specified. Demonstrate that this function works by using it in the following ways:

a. Draw 5 circles in a row, each with increasing radii (10, 20, 30…), just touching each other, each composed of 30 points.

b. Draw 5 regular polygons in a row, each with an increasing number of points (3, 4, 5…), each with a radius of 50 pixels.

void drawCircle ( Vec2d c, int r, int numberOfPoints) {
	glBegin(GL_POLYGON);
	glColor3f(0,0,0);
	for(int i=0;i < numberOfPoints;i++){
		float angle = 2*PI / numberOfPoints * i;
		float x = sin(angle) * r;
		float y = cos(angle) * r;
		Vec2d p(x,y);
		p = p+c;
		glVertex2f(p.x,p.y);
	}
	glEnd();
}
//also draws the regular polygons
void drawTouchingCircles()
{
	int numberOfCircles = 5;
	int nPoints = 29;
	Vec2d origin(100,100);
	for(int i=0; i<=numberOfCircles; i++)
	{
		
		float r = i*20;//radius	
		float dx = (r*2)-20;//offset
		Vec2d shift(dx,0);
		origin = origin+shift;
		origin.print();
		//draw circles touching each other
		drawCircle(origin,r,nPoints);
		//draw polygons with varying points
		drawCircle(Vec2d(i*100,300),50,i+2);
	}
}

Compform Assignment 2 - Problem 1 · posted by vaibhav bhawsar 382 days ago

Problem 1. Complete the Vec2d class. Add the following methods to the class:

a. Subtract one vector from another and return the resulting vector.
b. Divide a vector by a float and return the resulting vector.
c. Calculate the length of a vector using Pythagorean theorem and return the resulting float.

Vec2d.h

Vec2d.cpp

Comment

CompuForm Assigment 1: commented Main.cpp · posted by vaibhav bhawsar 389 days ago

The commented file:
main.txt

Comment

CompuForm Assigment 1: grid · posted by vaibhav bhawsar 389 days ago

void drawGrid ( void )
{
	//the color of the line
	glColor3f(.8,.8,.8);	
	//draw lines
	glBegin(GL_LINES);
	//horizontal line
	for(int h = 0 ; h < windowH/10 ; h++ ){
		glVertex2f ( 0 , h*10 );
		glVertex2f ( windowW , h*10 );
		//vertical lines
		for(int v = 0 ; v < windowW/10 ; v++ ){
			glVertex2f(v*10 , windowH );
			glVertex2f(v*10 , 0);
		}
	}
        glEnd();
	//draw points
	glColor3f(.4,.4,.4);
	glPointSize(3);		
	glBegin(GL_POINTS);
	int numberOfDivisions = 10;
	for(int h = 0 ; h <= windowH/numberOfDivisions ; h++){
		for(int v = 0 ; v <= windowW/numberOfDivisions ; v++){
			glVertex2f(v*numberOfDivisions, h*numberOfDivisions);
		}
	}
	glEnd();
}

CompuForm Assigment 1: landscape · posted by vaibhav bhawsar 389 days ago

void drawLand ( void )
{
	float c = .00392;
	//glPolygonMode(GL_BACK,GL_LINE);
	glBegin(GL_QUADS);
	glColor3f(c*164,c*164,c*164);
	glVertex2f(0,windowW);
	glColor3f(c*60,c*95,c*105);
	glVertex2f(0,windowH/2);
	glVertex2f(windowW,windowH/2);
	glColor3f(c*224,c*224,c*224);
	glVertex2f(windowW,windowH);
	glEnd();
	// //
	glBegin(GL_QUADS);
	glColor3f(c*0,c*60,c*60);
	glVertex2f(0,windowH/2);
	glColor3f(c*66,c*105,c*60);
	// //
	glVertex2f(0,0);
	glVertex2f(windowW,0);
	glColor3f(c*66,c*105,c*60);
	glVertex2f(windowW,windowH/2);
	glEnd();
	// //	
	float x = 40;	
	//hill1
	glBegin(GL_TRIANGLES);
	glColor3f(c*60,c*80,c*60);
	glVertex2f(x+60,windowH/2+(70)+(mouseY/3));
	glColor3f(c*16,c*105,c*60);
	glVertex2f(x+180,windowH/2);
	glColor3f(c*0,c*60,c*60);
	glVertex2f(x,windowH/2);
	glEnd();
	// //
	//hill3
	glBegin(GL_TRIANGLES);
	glColor3f(c*60,c*80,c*60);
	glVertex2f(x+490,windowH/2+(120)+(mouseY/6));
	glVertex2f(x+600,windowH/2);
	glColor3f(c*0,c*60,c*60);
	glVertex2f(x+190,windowH/2);
	glEnd();
	// //
	//hill2
	glBegin(GL_TRIANGLES);
	glColor3f(c*60,c*80,c*60);
	glVertex2f(x+190,windowH/2+(100)+(mouseY/6));
	glVertex2f(x+300,windowH/2);
	glColor3f(c*0,c*60,c*60);
	glVertex2f(x+100,windowH/2);
	glEnd();
	// //
	//hill4
	glBegin(GL_TRIANGLES);
	glColor3f(c*60,c*80,c*60);
	glVertex2f(x+590,windowH/2+(70)+(mouseY/3));
	glColor3f(c*16,c*105,c*60);
	glVertex2f(x+690,windowH/2);
	glColor3f(c*0,c*60,c*60);
	glVertex2f(x+490,windowH/2);
	glEnd();
	// //
	//cloud
	float f = mouseX*.318/(255);
	glBegin(GL_TRIANGLE_FAN);
	glColor4f(c*53,c*230,c*233,mouseX*.318/(255));
	glVertex2f(161,507);
	glVertex2f(161,523);
	glVertex2f(174,527);
	glVertex2f(187,523);
	glColor4f(c*10,c*150,c*233,mouseX*.318/(255));
	glVertex2f(195,515);
	glVertex2f(191,497);
	glVertex2f(179,487);					
	glVertex2f(174,487);	
	glVertex2f(161,495);
	glVertex2f(151,488);
	glVertex2f(144,487);
	glVertex2f(140,492);
	glVertex2f(135,492);
	glVertex2f(129,495);
	glVertex2f(128,501);
	glColor4f(c*53,c*230,c*233,mouseX*.318/(255));
	glVertex2f(133,508);
	glVertex2f(139,512);
	glVertex2f(151,519);
	glVertex2f(161,523);					
	glEnd();
	// //
	//river
	float xr = windowW/2+(mouseX);
	float yr = windowH/2;	
	glColor4f(c*53,c*230,c*233,.1);	
	glBegin(GL_TRIANGLE_STRIP);
	//left
	glVertex2f(windowW/2-(10),windowH/2);
	//right
	glVertex2f(windowW/2+40,windowH/2);
	glVertex2f(windowW/2-(xr/5),yr-20);
	glVertex2f(xr,yr-10);
	glVertex2f(windowW/2-(xr/4.5),yr-40);	
	glVertex2f(xr,yr-20);
	glVertex2f(windowW/2-(xr/4.3),yr-50);	
	glVertex2f(xr+20,yr-60);
	glVertex2f(windowW/2-(xr/4),yr-60);	
	glVertex2f(xr+40,yr-80);
	glVertex2f(windowW/2-(xr/3.5),yr-80);	
	glVertex2f(xr+60,yr-100);
	glVertex2f(windowW/2-(xr/3),yr-100);	
	glVertex2f(xr+80,yr-120);
	glVertex2f(windowW/2-(xr/2.5),yr-120);	
	glVertex2f(xr+100,yr-140);
	glVertex2f(windowW/2-(xr/2),yr-140);	
	glVertex2f(xr+120,yr-160);
	glVertex2f(windowW/2-(xr/1.5),yr-160);	
	glVertex2f(xr+140,yr-180);	
	glVertex2f(windowW/2-(xr),60);	
	glVertex2f(xr+180,0);
	glVertex2f(windowW/2-(xr),0);	
	glEnd();	
}

CompuForm Assigment 1: portrait · posted by vaibhav bhawsar 389 days ago

void drawPortrait( void )
{
	//glPolygonMode(GL_BACK,GL_LINE);
	glBegin(GL_TRIANGLE_FAN);
	glColor3f(.4,.4,.4);
	glVertex2f(400,285);
	glVertex2f(380,93);
	glVertex2f(360,130);
	glVertex2f(338,168);
	glVertex2f(310,176);
	glVertex2f(272,180);
	glVertex2f(260,183);
	glVertex2f(253,190);
	glVertex2f(251,198);
	glVertex2f(253,207);
	glVertex2f(254,218);
	glVertex2f(250,226);
	glVertex2f(243,230);
	glVertex2f(240,236);
	glVertex2f(243,241);
	glVertex2f(246,246);
	glVertex2f(238,249);
	glVertex2f(232,255);
	glVertex2f(234,265);
	glVertex2f(241,280);
	glVertex2f(231,287);
	glVertex2f(227,295);
	glVertex2f(227,303);
	glVertex2f(231,312);
	glVertex2f(242,324);
	glVertex2f(252,336);
	glVertex2f(262,362);
	glVertex2f(264,375);
	glVertex2f(259,391);
	glVertex2f(270,421);
	glVertex2f(281,444);
	glVertex2f(301,461);
	glVertex2f(344,486);
	glVertex2f(386,500);
	glVertex2f(424,501);
	glVertex2f(455,491);
	glVertex2f(495,455);
	glVertex2f(521,420);
	glVertex2f(521,420);
	glVertex2f(532,346);
	glVertex2f(528,320);
	glVertex2f(521,310);
	glVertex2f(518,289);
	glVertex2f(512,266);
	glVertex2f(511,239);
	glVertex2f(519,182);
	glVertex2f(522,150);
	glVertex2f(500,129);
	glVertex2f(461,102);							
	glVertex2f(415,88);
	glVertex2f(398,87);	
	glVertex2f(380,93);
	glEnd();
        // //
	//eyes
	glBegin(GL_TRIANGLE_STRIP);
	glColor3f(.2,.2,.2);
	glVertex2f(270,357);	
	glVertex2f(273,364);
	glVertex2f(272,348);
	glVertex2f(278,364);
	glVertex2f(277,346);
	glVertex2f(282,363);
	glVertex2f(282,349);
	glVertex2f(286,361);
	glVertex2f(287,352);
	glVertex2f(288,360);
	glVertex2f(290,356);
	glEnd();
}