derBaum.com a page about Economics, Web Development and food.  

CS148: Computer Graphics

During my computer graphics class at Stanford, I had the chance to model some trees. Studding the standard books of computer graphics I quickly found my way into OpenGL.

Generated using simple recursive algorithms for transformation in OpenGL
void fractal2D(double steps) {
 if(steps > 20) set color brown:
 else set color to a random green;
 drawRectangle(-steps/20,0,steps/20,steps); // 1:20
 glTranslated(0, steps, 0); // move to the top of the rectangle
 if(steps > 2) {
  glPushMatrix();
  glRotatef(-RandInt(90), 0, 0, 1);
  fractal2D(steps/2); // start first branch
  glPopMatrix();
  glRotatef(RandInt(90), 0, 0, 1); 
  fractal2D(steps/1.2); // start secound branch
 }
}

Labels: ,