Thursday, March 26, 2009

Wednesday, March 25, 2009

First OpenGL Assignment

After reading the articles posted, I love the way that OpenGL takes advantage of the graphics card by directly accessing its memory and, therefore saving the processor a good amount of work. While this may not be evident in the smaller assignments and projects that we are currently doing, any way to relieve the processor and speed up a program is certainly going to help if programming a game that must use search trees for its AI or any other very time consuming operation. Another great thing about OpenGL seems to be its versatility. It seems rather rare in my limited experience to find a library that can be used in a variety of languages as OpenGL is. Python is hopefully the language that I plan on learning next so I am somewhat excited that what I learn about OpenGL I will be able to use in Python as well. The fact that OpenGL ES can be used for mobile devices further exhibits this versatility, making it a very useful library to know since it can be used in so many platforms. From what I have read, it also appears that many of the commands are relatively straightforward and easy to use. All of this combined has made me excited to learn more.

The second part of this assignment was to create a Bezier curve in OpenGL. The curve rotates when you hit the arrow button.
















Finally, I created a multi-colored 3-d cube. This also rotates when the arrows are pushed. I plan on expanding this tomorrow, but I have this so far so might as well post it.











The basic outline of a house using 3d OpenGGL commands.

Friday, March 6, 2009

Compiling and Running glut on my PC

Here is the simple.cpp program running on my personal computer. (Proof I can get it to work I guess)

Thanks to Michael for the easy to follow step by step instructions.

Project 1: Circles


The purpose of project 1 was to replicate an image by Anthony Mattox that included circles placed within a circular border. Next we had to come up with a variation of that image of our own. The first 3 images are replications, followed by a variety of variations made by creating different color or saturation functions that changed based on the circles position in the image. It took a few days to get this posted due to trying to upload .pdfs of the images with no success, but here they are as .jpegs.







































































































import processing.pdf.*;

float borderDiam=700;
int numCircs=1000000;//change back to at least 1000000
boolean overlap;
int count=0;
Circ[] balls = new Circ[numCircs];
int diameter;
void setup(){
background(255);

size(700,700);
noLoop();
beginRecord(PDF, "T2BRainbow1.pdf");
// stroke(100);
smooth();
//ellipse(350,350,700,700);
noStroke();
int count=0;

for (int i=0;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/10)+10);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/20)+10);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/30)+5);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}
for (int i=count;i float x=random(borderDiam);
float y=random(borderDiam);
float diameter=(random(borderDiam/30)+2);
Circ temp=new Circ(x,y,diameter);
if (inBorder(x,y,diameter)&&collide(x,y,diameter,count)){
balls[count]=temp;
count++;
}
}

System.out.println(count);
for (int i = 0; i < count; i++){
balls[i].display();
}
endRecord();

}
void draw(){

}
boolean inBorder(float x, float y, float diameter){
float distToCenter=dist(x,y,borderDiam/2,borderDiam/2);
float distToEdge= distToCenter+diameter/2;
if (distToEdge>borderDiam/2){
return false;
}
else return true;


}
boolean collide(float x, float y, float d, int numCircles){
int diameter=(int)d;
for (int i = 0; i < numCircles; i++){
float distance = dist(x, y, balls[i].x, balls[i].y);
float minDist = balls[i].diameter/2 + diameter/2;
if (distance < minDist){
return false;
}

}
return true;
}

class Circ{
float x, y;
float diameter;
int id;

boolean display = true;
boolean inBorder=true;
float col;
float sat;
float bright;
float gray;
Circ(float xin, float yin, float diameter){
x = xin;
y = yin;
this.diameter = diameter;
//blue 195
//cool green 145
//pink 300
//red 340
//yellow green 60
//0 red orange
//for a rainbow coloring
//col=((dist(borderDiam/2,borderDiam/2,x,y))/(borderDiam/720));
//col= ((borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/(borderDiam/720));
//col=+(random(20));
col=y/(borderDiam/360)+random(40);
sat=((dist(borderDiam/2,borderDiam/2,x,y))/(borderDiam/200));
bright=((borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/(borderDiam/100));
gray=(borderDiam/2-dist(x,y,borderDiam/2,borderDiam/2))/1.2;

}

void display(){
colorMode(HSB,360,100,100);
fill(col,sat,100);
//fill(gray);
ellipse(x, y, diameter, diameter);
}
}