Compform Assignment 2 - Problem 1 · posted by vaibhav bhawsar Sep 21, 2007

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

Chance Procedures - John Cage · posted by vaibhav bhawsar Sep 18, 2007

Added here for this composition’s map like qualities.. looking at it as though it were a process of creating, mapping through discovery and indeterminancy

Chance as not a way of giving up choices.
My choices consist in choosing what questions to ask. – John Cage

Comment

CompuForm Assigment 1: commented Main.cpp · posted by vaibhav bhawsar Sep 14, 2007

The commented file:
main.txt

Comment

CompuForm Assigment 1: grid · posted by vaibhav bhawsar Sep 14, 2007

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 Sep 14, 2007

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 Sep 14, 2007

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();
}

HMC6352 Sparkfun Compass Module and Arduino · posted by vaibhav bhawsar Jul 16, 2007

Ok so I struggled a bit to get this to work so it makes sense to post it here in case you are having a similar problem getting HMC6352 compass module to work with Arduino. The code below is not mine- I got it from Sparkfun’s forums

Using Arduino NG rev C board and Arduino IDE v.0008. It didn’t work when I compiled and uploaded the code with v.0007. So don’t use it. SDL and SCL lines don’t have any pullup resistors in my setup. Probably because v.0008 enables the pullup resistors on ATmega168.

From v.0008 UPDATES file
Activating TWI/I2C pullup resistors on the ATmega168 (in addition to the ATmega8).

NOTES

*Using Arduino NG rev C board and Arduino IDE v.0008

*SDA to Analog pin 4 and SCL to analog pin 5

*No pullup resistors on SDA and SCL

*Using 3v instead of 5v to the Vcc of the compass module.

CODE:

#include <Wire.h>
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
void setup()
{
// Shift the device's documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1;   // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
pinMode(ledPin, OUTPUT);      // Set the LED pin as output
Wire.begin();
}
void loop()
{
  // Flash the LED on pin 13 just to show that something is happening
  // Also serves as an indication that we're not "stuck" waiting for TWI data
  ledState = !ledState;
  if (ledState) {
    digitalWrite(ledPin,HIGH);
  }
  else
  {
    digitalWrite(ledPin,LOW);
  }
  // Send a "A" command to the HMC6352
  // This requests the current heading data
  Wire.beginTransmission(slaveAddress);
  Wire.send("A");              // The "Get Data" command
  Wire.endTransmission();
  delay(10);                   // The HMC6352 needs at least a 70us (microsecond) delay
  // after this command.  Using 10ms just makes it safe
  // Read the 2 heading bytes, MSB first
  // The resulting 16bit word is the compass heading in 10th's of a degree
  // For example: a heading of 1345 would be 134.5 degrees
  Wire.requestFrom(slaveAddress, 2);        // Request the 2 byte heading (MSB comes first)
  i = 0;
  while(Wire.available() && i < 2)
  { 
    headingData[i] = Wire.receive();
    i++;
  }
  headingValue = headingData[0]*256 + headingData[1];  // Put the MSB and LSB together
  Serial.print("Current heading: ");
  Serial.print(int (headingValue / 10));     // The whole number part of the heading
  Serial.print(".");
  Serial.print(int (headingValue % 10));     // The fractional part of the heading
  Serial.println(" degrees");
  delay(500);
} 

Kerouac where are you? · posted by vaibhav bhawsar Jun 06, 2007

I am in San Fran..cisco. I have seen the bay. I am as west as one could get. I saw the absurdest commemorating sea lions on a deck. I loathe the food here. I can’t make out the difference between the homeless and the homed. I am a yahoo. And not a google. Nevertheless am branded. But I still make economically senseless things. I love no thought, but am full of it. I walk a lot. I walk couple of miles. I walk uphill and eventually downhill. I walk the third street. I think BART is a funny name for a public transport system. And so is MUNI. I think its a joke. I am surrounded by good doers, sudoers. I am amidst java, downtown and strange weather. I HO java not again! I have seen Kerouac and his meager 40 foot long street, so much for travelling 5000 miles umpteen times and writing great spontaneous prose. Me for an I.

Older Newer