Tuesday, July 14, 2009

Monday, May 4, 2009

Final Project

For this final project i decided to do the L System trees.  I think that when I looked at all of the different project ideas I thought that the recursive tree would be the easiest.  


The first thing that I thought about when I saw the trees were was the L Systems example in Processing's examples.  The code for this project was so short that i figured that I would be fine doing a 3D l system tree.  Triangles in chapter 3 is the base of my program.  After I became familiar with all of the methods and whatnot I decided to weed out what I didn't need.  So i open 2 other projects from the Superbible and deleted everything in them and rewrote the entire program with only what i needed and no comments. 

I also looked at the wikipedia entry, which makes sense but i did not really use it to do any of the programming for the project. 

 


 The first thing that I knew that I would need was a cylinder, which I found at this site.  It turns out that this site had a lot of extra material that was useless but I did get the few lines of code needed to make a cylinder.  


Once I learned how to draw the cylinder I started playing around with the translation matrices to get it to the bottom and then.  Once I figured the translations I started playing with the rotations and from there it has just kind of been adjusting the different settings to find what looks the best.  I have tried to use some different colors but it seems that open GL wont change the colors when the branch length gets short enough.


The first tree is just random placements and it was the first tree that I made.  I really didn't know what was going on so the branches kind of go in different directions.  The second shoots out about 8 branches from every branch by rotating once on the x axis and then one of the y axis.  Once I got this code working i found the polygon garden website from the blog and saw their approach to rotations I then tried one similar to theirs which kind of shoots off branches like a sprinkler shooting off water.  For the third one the code is about half as long.




cboard.cprogramming.com/game-programming/71357-need-some-help- drawing-cylinder-opengl.html

processing.org/

opengl.org/superbible

http://www.director-online.com/buildArticle.php?id=1119



Sunday, April 5, 2009

Project 2




After just finishing file handling in Java I thought that it would be difficult in C but it was not so bad.  For my project I have just changed the sphereworld example from the open GL Superbible by Richard Wright.  For my obj files I had to go into them and delete some of the garbage so that the program would only read the vertices and faces and not get caught up in the texture nonsense.  The tutorials from the web site were pretty helpful for the C file handling.  I got the .obj files from this site.  

Thursday, March 26, 2009

I tried to get the second part of the homework working but it just wasn't havin it.  This one came out ok and i played around with the look at and the translate.

Thursday, March 19, 2009

open gl is not so bad


So here are the two assignments.  the curve came out pretty easily but the coloring on the house is not so great,  all of the walls are there but from the angle that the camera is at you cannot see them.  I need to just paint both sides of the wall.

1.  The thing that I find the most interesting about the openGL stuff is how some of the process that the processor would normally do are now being done by the graphics card which is probably under utilized by most computer users.  I also thought that it was pretty cool that by pawning off some of the responsibilities onto the graphics hardware the machines are able to use less process and save battery overall, even if it is not that much.  I also think the it is cool that processing and python are open to utilizing some of the open gl stuff as well.


2. Some of the things are new in this program are the glEnable and frontface that say they are used for hidden surface removal, the way the polygons face and the way some calculations are done.  Also the glLight functions are new to this project.

Wednesday, March 18, 2009


here is the proof that open GL works on my machine, buyakashaw

Tuesday, March 3, 2009

Circles





















These are 2 screen shots of my project.  Clearly I choose the circles.  The idea originally came from Anthony Mattox's website.  The color are random using HSV color.  The way that I went about doing this project was creating a circle object with a random X,Y, and radius value and then testing these values against the circles that have already been drawn to see if they are too close together, ie touching/overlapping.  If they passed the test then the circle was drawn.  These pictures have 5000 circles, the highest that I was able to get to was 6851, but because processing doesn't have a flush function(or i dont know it) i was never able to see it.  thank you come again 

Sunday, February 15, 2009

multiple triangles

triangle


















ZG
int width = 200;
int height = 200;
float[][] rotateMatrix = new float[2][2];

void setup()
{
  size (width,height);
  noLoop();
}

void draw()
{
  int x0, y0, x1, y1, x2, y2;
  x0 = int(random(width));
  y0 = int(random(height));
  x1 = int(random(width));
  y1 = int(random(height));
  x2 = int(random(width));
  y2 = int(random(height));
  for (float i =0; i <>
  {
  float rotateAngle = i * PI;
  rotation(x0, y0, x1, y1, x2, y2, rotateAngle);
  }
}

void rotation(int x0, int y0, int x1, int y1, int x2, int y2, float rotateAngle)
{
  buildMatrix(rotateAngle);
  
float[][] trianglePoints = {{x0, y0}, {x1, y1}, {x2, y2}};
  triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
  
  trianglePoints = multiply(trianglePoints, rotateMatrix);
  triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
  
  
}
float[][] multiply(float[][]a, float[][]b)
{
  float[][]c = new float[a.length][b[0].length];
  for (int i = 0; i <>
    for (int j = 0; j <>
      for (int k = 0; k <>
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return c;
}
void buildMatrix(float rotateAngle)
{
  rotateMatrix[0][0] = cos(rotateAngle);
  rotateMatrix[0][1] = sin(rotateAngle);
  rotateMatrix[1][0] = -sin(rotateAngle);
  rotateMatrix[1][1] = cos(rotateAngle);
}

Friday, February 6, 2009

Project

I have not really though about what kind of project that i want to do. The things that I saw that I though might be cool were the spiky-ball-craziness thing from the processing side. I would like to try to do something in node box since I now have a Mac.

Sunday, February 1, 2009

Cubic Click



int x0, y0, x1, y1, x2, y2, x3, y3;
int count = 0;
void setup()
{
  size(400,400);
}
void draw()
{
}

void mousePressed()
  if (count == 0)
  {
    x0 = mouseX;
    y0 = mouseY;
    point(x0, y0);
    count++;
  }
  else if (count == 1)
  {
    x1= mouseX;
    y1 = mouseY;
    count++;
  }
  else if (count == 2)
  {
    x2 = mouseX;
    y2 = mouseY;
    count++;
  }
  else
  {
    x3 = mouseX;
    y3 = mouseY;
    CubicCurv(x0, y0, x1, y1, x2, y2, x3, y3);
    count = 0;
  }
}

void CubicCurv(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
  float x, y;
  for(float t = 0 ; t <>
  {
    x= (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1+ 3*(1-t)*(1-t)*t*t*x2 + t*t*t*x3;
    y= (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1+ 3*(1-t)*(1-t)*t*t*y2 + t*t*t*y3;
    point(x,y);
  }
}

5 triangles





void setup()
{
  size(500,500);
  noLoop();
}

void draw()
{
  for (int i = 0 ; i<>
  {
    drawTriangle(int(random(500)), int(random(500)), int(random(500)), int(random(500)), int(random(500)), int(random(500)));
  }
}
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2)
{
  line(x0, y0, x1, y1);
  line(x1,y1, x2,y2);
  line(x2, y2, x0, y0);
}

Thursday, January 22, 2009

Assignment 3 Bezier Curves



a

void setup()
{
  size(200,600);
  background(0);
  stroke(255);
}

void draw()
{
  LinCurv(15,150,75,15);
  LinCurv(50,120,120,160);
  LinCurv(130,130,170,25);
  QuadCurv(50,370,80,210,110,270);
  QuadCurv(90,380,140,290,190,390);
  CubicCurv(50,570,40,500,100,490,150,580);
  CubicCurv(120,500,110,410,170,420,190,510);
}

void LinCurv(int x0, int y0, int x1, int y1)
{
  for(float t=0; t <>
  {
    float x,y;
    
    x = x0 *(1-t)+ t * x1;
    y = y0 *(1-t)+ t*y1;
    point(x, y);
  }
}

void QuadCurv(int x0, int y0, int x1, int y1, int x2, int y2)
{
  float x,y;
  for(float t=0; t<>
  {
    x= (1-t)*(1-t)*x0 + 2*(1-t)*t*x1 + t*t*x2;
    y= (1-t)*(1-t)*y0 + 2*(1-t)*t*y1 + t*t*y2;
    point(x,y);
  }
}

void CubicCurv(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
{
  float x, y;
  for(float t = 0 ; t <>
  {
    x= (1-t)*(1-t)*(1-t)*x0 + 3 *(1-t)*(1-t)*t*x1+ 3*(1-t)*(1-t)*t*t*x2 + t*t*t*x3;
    y= (1-t)*(1-t)*(1-t)*y0 + 3 *(1-t)*(1-t)*t*y1+ 3*(1-t)*(1-t)*t*t*y2 + t*t*t*y3;
    point(x,y);
  }
}




Wednesday, January 14, 2009

Homework 2


Homework 2


void setup()
{
size(200,200);
background(0);
}

void draw()
{
  drawWeb(150);
  drawLine(120,10,170,150);
  drawCircle(100,100,15);
}

void drawCircle(int x0, int y0, int radius)
{
  int f = 1 - radius;
  int ddF_x = 1;
  int ddF_y = -2 * radius;
  int x = 0;
  int y = radius;
  
  point(x0, y0 + radius);
  point(x0, y0 - radius);
  point(x0 + radius, y0);
  point(x0 - radius, y0);
  
  while(x< ya)
  {
    ddF_x = 2*x + 1;
    ddF_y = -2*y;
    f = x*x +y*y - radius*radius + 2*x-y +1;
    if (f>0)
    {
      y--;
      ddF_y += 2;
      f += ddF_y;
    }
    x++;
    ddF_x += 2;
    f+= ddF_x;
    point(x0 + x, y0+y);
    point(x0 - x, y0+y);
    point(x0 + x, y0-y);
    point(x0 - x, y0-y);
    point(x0 + y, y0 + x);
    point(x0 - y, y0+x);    
    point(x0 + y, y0-x);
    point(x0 -y, y0-x);
  }
}
void drawLine(int x0, int y0, int x1, int y1)
{
  
  
 int rise = y1 - y0; 
 int run = x1 - x0;
 float error = 0;
 float slope = (float)rise/run;
 int y = y1;
 
 for(int x=x0; x <= x1;x++)
 {
 point(x,y);
 error = error + slope;
 if(abs(error) >= 0.5)
 {
   y=y+1;
   error -= 1.0;
 }
 }
 
}

void drawWeb(int siz)
{
for (int i = 1; i < i =" i+5)
{
  stroke(255);
  line(0, siz, i, 0);
  siz--;
}


for (int i = 1; i < i =" i+5)
{
  stroke(255);
  line(siz, 0, 0, i);
  siz--;
}
}