Fractal Clipping Menggunakan OpenGL

Kali ini kita akan membahas materi Grafika komputer  “Fractal Clipping” yaitu berupa grafis visualization dengan memanfaatkan Glut library langsung aja cek codingannya, saya menggunakan Codeblocks sebagai compilernya.

fractal

#include <windows.h>
#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>

const GLfloat PHI = 3.14159;
const GLfloat LS = 0.75;
const GLfloat DTHETA = PHI / 5;

static void resize (int width, int height)
{
const float ar = (float) width / (float) height;
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0,0.0,7.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,0.5,0.0,0.0,0.0,0.0,0.1,0.0);
glClearColor(1.0f,1.0f,1.0f,10.f);
}

static void displayobj(GLint d, GLfloat x, GLfloat y, GLfloat z, GLfloat l, GLfloat t)
{
GLfloat xl = x + l * cos(t);
GLfloat yl = y + l * sin(t);
GLfloat zl = z + l * 2*cos(t)*sin(t);
glBegin(GL_LINES);
glVertex3f(x,y,z);
glVertex3f(xl, yl, zl);
glEnd();
glFlush();
if (d > 1)
{
displayobj(d-1, xl, yl, zl, l*LS, t+DTHETA);
displayobj(d-1, xl, yl, zl, l*LS, t-DTHETA);
}
glFlush();

}

static void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5f,0.0f,0.0f);
displayobj(8,0,0,1,0.25,PHI/2.0);
displayobj(8,0,0,1,0.25,PHI);
displayobj(8,0,0,1,0.25,PHI/-2.0);
displayobj(8,0,0,1,0.25,2*PHI);
glRotated(2.0,0.1,0.0,0.0);
//glRotated(-0.3,0.1,0.0,0.0);
glutSwapBuffers();
}

static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case ‘q’:
case 13 :
exit(0);
break;
}

glutPostRedisplay();
}

static void idle(void)
{
glutPostRedisplay();
}

int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow(“GLUT Shapes”);

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);

glutMainLoop();

return EXIT_SUCCESS;
}

One thought on “Fractal Clipping Menggunakan OpenGL

  1. Anonim mengatakan:

    Bravo !!!😀

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s