Computer Graphics using GLUT projects Source Code : Tiles Pattern


Hello !!! Today I want to share my past project in computer graphics using Glut. For you who still do not have glut for C library, you can download it in here. I also give instruction how to installed it in your project here. And here are the projects for this tiles pattern.Actually, I made many of them in the past. But I’ll post them on by one in the future.

This project of mine is tiles pattern. Most of it contains polygon lines. The result is just like  picture below :

ScreenShot_TugasPolaUbin.JPG

So You know computer graphics is such an existence which make you drawing with code instead of pencil or pen :p. So yeah the listing must be so long since this project used procedural programming. here are the source code for this project :

// Created by: Dean Nicholls
// Date: 18th June 2010
// Created For: http://www.levelbylevel.com
//
// This is a small OpenGL application which will display a
// blue sphere on a black background.
//
// This Program was created to acompany the tutorial
// for setting up CodeBlocks, MinGW, OpenGL and GLUT.
// Found at: http://www.levelbylevel.com
//
// It is not intended to be a guide or even a good
// template for building a graphic application. It is
// therefore not properly commented or efficient.
// However feel free to use this code in any way you wish.
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>


void userdraw(void){

    /***GARIS MIRING***/
    glBegin(GL_LINES); // GARIS MIRING 1,2,3
            glColor3f(1, 0, 0.302);
            glVertex2f( -500. , 450.  );
            glVertex2f( 450.  , -500 );

            glVertex2f( -500. , 500.  );
            glVertex2f( 500.  , -500 );

            glVertex2f( -450. , 500.  );
            glVertex2f( 500.  , -450 );
    glEnd();

    glBegin(GL_LINES); // GARIS MIRING 4,5,6
            glColor3f(1, 0, 0.302);
            glVertex2f( 450. , 500.  );
            glVertex2f( -500.  , -450. );

            glVertex2f( 500. , 500.  );
            glVertex2f( -500.  , -500 );

            glVertex2f( 500. , 450.  );
            glVertex2f( -450.  , -500 );
    glEnd();

    glBegin(GL_LINES); // GARIS MIRING 7,8,9
            glColor3f(1, 0, 0.302);
            glVertex2f( -50. , 500.  );
            glVertex2f( -50.  , -500. );

            glVertex2f( 0. , 500.  );
            glVertex2f( 0.  , -500 );

            glVertex2f( 50. , 500.  );
            glVertex2f( 50.  , -500 );
    glEnd();

     glBegin(GL_LINES); // GARIS MIRING 10,11,12
            glColor3f(1, 0, 0.302);
            glVertex2f( -500. , 50.  );
            glVertex2f( 500.  , 50. );

            glVertex2f( -500. , 0.  );
            glVertex2f( 500.  , 0. );

            glVertex2f( -500. , -50.  );
            glVertex2f( 500.  , -50 );
    glEnd();
    /********************************/

    glBegin(GL_POLYGON); //Bentuk C
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(-475. , 75. );//1
            glVertex2f(-400. , 75. ); //2
            glVertex2f(-400. , 100. ); //3
            glVertex2f(-425. , 100. ); //4
            glVertex2f(-425. , 125. ); //5
            glVertex2f(-450. , 125. ); //6
            glVertex2f(-450. , 150. ); //7
            glVertex2f(-475. , 150. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk D
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(-475. , -75. );//1
            glVertex2f(-400. , -75. ); //2
            glVertex2f(-400. , -100. ); //3
            glVertex2f(-425. , -100. ); //4
            glVertex2f(-425. , -125. ); //5
            glVertex2f(-450. , -125. ); //6
            glVertex2f(-450. , -150. ); //7
            glVertex2f(-475. , -150. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk G
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(475. , -75. );//1
            glVertex2f(400. , -75. ); //2
            glVertex2f(400. , -100. ); //3
            glVertex2f(425. , -100. ); //4
            glVertex2f(425. , -125. ); //5
            glVertex2f(450. , -125. ); //6
            glVertex2f(450. , -150. ); //7
            glVertex2f(475. , -150. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk C
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(475. , 75. );//1
            glVertex2f(400. , 75. ); //2
            glVertex2f(400. , 100. ); //3
            glVertex2f(425. , 100. ); //4
            glVertex2f(425. , 125. ); //5
            glVertex2f(450. , 125. ); //6
            glVertex2f(450. , 150. ); //7
            glVertex2f(475. , 150. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk J
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(-75. , 475. );//1
            glVertex2f(-150. , 475. ); //2
            glVertex2f(-150. , 450. ); //3
            glVertex2f(-125. , 450. ); //4
            glVertex2f(-125. , 425. ); //5
            glVertex2f(-100. , 425. ); //6
            glVertex2f(-100. , 400. ); //7
            glVertex2f(-75. , 400. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk E
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(-75. , -475. );//1
            glVertex2f(-150. , -475. ); //2
            glVertex2f(-150. , -450. ); //3
            glVertex2f(-125. , -450. ); //4
            glVertex2f(-125. , -425. ); //5
            glVertex2f(-100. , -425. ); //6
            glVertex2f(-100. , -400. ); //7
            glVertex2f(-75. , -400.); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk F
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(75. , -475. );//1
            glVertex2f(150. , -475. ); //2
            glVertex2f(150. , -450. ); //3
            glVertex2f(125. , -450. ); //4
            glVertex2f(125. , -425. ); //5
            glVertex2f(100. , -425. ); //6
            glVertex2f(100. , -400. ); //7
            glVertex2f(75. , -400. ); //8
    glEnd();

    glBegin(GL_POLYGON); //Bentuk I
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(75. , 475. );//1
            glVertex2f(150. , 475. ); //2
            glVertex2f(150. , 450. ); //3
            glVertex2f(125. , 450. ); //4
            glVertex2f(125. , 425. ); //5
            glVertex2f(100. , 425. ); //6
            glVertex2f(100. , 400. ); //7
            glVertex2f(75. , 400. ); //8
    glEnd();



    glBegin(GL_POLYGON); //kotak B
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(0. , 300. );
            glVertex2f(-300. , 0. );
            glVertex2f(0. , -300. );
            glVertex2f(300. , 0. );
    glEnd();

    glBegin(GL_POLYGON); //kotak A
            glColor3f(0.808,0.031,1);
            glVertex2f(0. , 250. );
            glVertex2f(-250. , 0. );
            glVertex2f(0. , -250. );
            glVertex2f(250. , 0. );
    glEnd();

    /** Kanal **/
    glBegin(GL_POLYGON); // A1
            glColor3f(0.808,0.031,1);
            glVertex2f(-500. , -50. );
            glVertex2f(-475. , -25. );
            glVertex2f(-350. , -25. );
            glVertex2f(-325. , -50. );
    glEnd();

    glBegin(GL_POLYGON); //A2
            glColor3f(0.808,0.031,1);
            glVertex2f(-500. , 50. );
            glVertex2f(-475. , 25. );
            glVertex2f(-350. , 25. );
            glVertex2f(-325. , 50. );
    glEnd();

    glBegin(GL_POLYGON); //A2
            glColor3f(0.808,0.031,1);
            glVertex2f(500. , 50. );
            glVertex2f(475. , 25. );
            glVertex2f(350. , 25. );
            glVertex2f(325. , 50. );
    glEnd();

    glBegin(GL_POLYGON); //A2
           glColor3f(0.808,0.031,1);
            glVertex2f(500. , -50. );
            glVertex2f(475. , -25. );
            glVertex2f(350. , -25. );
            glVertex2f(325. , -50. );
    glEnd();

    glBegin(GL_POLYGON); //A2
           glColor3f(0.808,0.031,1);
            glVertex2f(50. , 500. );
            glVertex2f(25. , 475. );
            glVertex2f(25. , 350. );
            glVertex2f(50. , 325. );
    glEnd();

    glBegin(GL_POLYGON); //A2
           glColor3f(0.808,0.031,1);
            glVertex2f(-50. , 500. );
            glVertex2f(-25. , 475. );
            glVertex2f(-25. , 350. );
            glVertex2f(-50. , 325. );
    glEnd();

    glBegin(GL_POLYGON); //A2
           glColor3f(0.808,0.031,1);
            glVertex2f(50. , -500. );
            glVertex2f(25. , -475. );
            glVertex2f(25. , -350. );
            glVertex2f(50. , -325. );
    glEnd();

    glBegin(GL_POLYGON); //A2
           glColor3f(0.808,0.031,1);
            glVertex2f(-50. , -500. );
            glVertex2f(-25. , -475. );
            glVertex2f(-25. , -350. );
            glVertex2f(-50. , -325. );
    glEnd();
    /**********************/

    /** RAlly **/
    float j=0;
    for(int i=0 ; i<7 ; i++){
        glBegin(GL_POLYGON); //Rally 1
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(-175. -j , 175. +j );
            glVertex2f(-175. -j , 125. +j );
            glVertex2f(-200. -j , 150. +j);
            glVertex2f(-200. -j, 200. +j);
            glVertex2f(-150. -j, 200. +j);
            glVertex2f(-125. -j, 175. +j);
        glEnd();
        j+=50.;
    }
    j=0;
    for(int i=0 ; i<7 ; i++){
        glBegin(GL_POLYGON); //Rally 2
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(175. +j , -175. -j );
            glVertex2f(175. +j , -125. -j );
            glVertex2f(200. +j , -150. -j);
            glVertex2f(200. +j, -200. -j);
            glVertex2f(150. +j, -200. -j);
            glVertex2f(125. +j, -175. -j);
        glEnd();
        j+=50.;
    }

    j=0;
    for(int i=0 ; i<7 ; i++){
        glBegin(GL_POLYGON); //Rally 2
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(-175. -j , -175. -j );
            glVertex2f(-175. -j , -125. -j );
            glVertex2f(-200. -j , -150. -j);
            glVertex2f(-200. -j, -200. -j);
            glVertex2f(-150. -j, -200. -j);
            glVertex2f(-125. -j, -175. -j);
        glEnd();
        j+=50.;
    }

    j=0;
    for(int i=0 ; i<7 ; i++){
        glBegin(GL_POLYGON); //Rally 2
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(175. +j , 175. +j );
            glVertex2f(175. +j , 125. +j );
            glVertex2f(200. +j , 150. +j);
            glVertex2f(200. +j, 200. +j);
            glVertex2f(150. +j, 200. +j);
            glVertex2f(125. +j, 175. +j);
        glEnd();
        j+=50.;
    }
    /*****************/

    /**SEGITIGA LUAR**/
    glBegin(GL_POLYGON); //Segitiga L
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(-300. , 0. );
            glVertex2f(-175. , -125. );
            glVertex2f(-500. , -450. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga M
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(300. , 0. );
            glVertex2f(175. , -125. );
            glVertex2f(500. , -450. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga N
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(300. , 0. );
            glVertex2f(175. , 125. );
            glVertex2f(500. , 450. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga O
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(-300. , 0. );
            glVertex2f(-175. , 125. );
            glVertex2f(-500. , 450. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga P
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(0. , -300. );
            glVertex2f(-125. , -175. );
            glVertex2f(-450. , -500. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga Q
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(0. , -300. );
            glVertex2f(125. , -175. );
            glVertex2f(450. , -500. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga R
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(0. , 300. );
            glVertex2f(125. , 175. );
            glVertex2f(450. , 500. );
    glEnd();

    glBegin(GL_POLYGON); //Segitiga S
            glColor3f(0.933, 0.271, 0.271);
            glVertex2f(0. , 300. );
            glVertex2f(-125. , 175. );
            glVertex2f(-450. , 500. );
    glEnd();
    /************************************/

    /** SEGITUGA DALAM**/
    glBegin(GL_POLYGON); //SD1
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(-450. , -375. );
            glVertex2f(-300. , -50. );
            glVertex2f(-200. , -125. );
    glEnd();

    glBegin(GL_POLYGON); //SD2
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(450. , -375. );
            glVertex2f(300. , -50. );
            glVertex2f(200. , -125. );
    glEnd();

    glBegin(GL_POLYGON); //SD3
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(450. , 375. );
            glVertex2f(300. , 50. );
            glVertex2f(200. , 125. );
    glEnd();

    glBegin(GL_POLYGON); //SD4
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(-450. , 375. );
            glVertex2f(-300. , 50. );
            glVertex2f(-200. , 125. );
    glEnd();

    glBegin(GL_POLYGON); //SD5
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(-375. , -450. );
            glVertex2f(-50. , -300. );
            glVertex2f(-125. , -200. );
    glEnd();

    glBegin(GL_POLYGON); //SD6
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(375. , -450. );
            glVertex2f(50. , -300. );
            glVertex2f(125. , -200. );
    glEnd();

    glBegin(GL_POLYGON); //SD7
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(375. , 450. );
            glVertex2f(50. , 300. );
            glVertex2f(125. , 200. );
    glEnd();

    glBegin(GL_POLYGON); //SD7
            glColor3f(0.973, 0.525, 0.525);
            glVertex2f(-375. , 450. );
            glVertex2f(-50. , 300. );
            glVertex2f(-125. , 200. );
    glEnd();
    /*************************************/

    glBegin(GL_POLYGON); //Bentuk K
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(0. , 75. );
            glVertex2f(-50. , 100. );//1
            glVertex2f(-100. , 50. ); //2
            glVertex2f(-75. , 0. );
            glVertex2f(-100. , -50. ); //3
            glVertex2f(-50. , -100. ); //4
            glVertex2f(0. , -75. );
            glVertex2f(50. , -100. ); //5
            glVertex2f(100. , -50. ); //6
            glVertex2f(75. , 0. );
            glVertex2f(100. , 50. ); //7
            glVertex2f(50. , 100. ); //8
    glEnd();

    glBegin(GL_POLYGON); // PANAH 1// P1
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(-100. , 0. );
            glVertex2f(-125. , 50. );
            glVertex2f(-175. , 50. );
            glVertex2f(-150. , 0. );
            glVertex2f(-175. , -50. );
            glVertex2f(-125. , -50. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 2// P2
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(100. , 0. );
            glVertex2f(125. , 50. );
            glVertex2f(175. , 50. );
            glVertex2f(150. , 0. );
            glVertex2f(175. , -50. );
            glVertex2f(125. , -50. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 3// P3
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(0. , 100. );
            glVertex2f(50. , 125. );
            glVertex2f(50. , 175. );
            glVertex2f(0. , 150. );
            glVertex2f(-50. , 175. );
            glVertex2f(-50. , 125. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 4// P4
            glColor3f(0.922, 0.165, 0.165);
            glVertex2f(0. , -100. );
            glVertex2f(50. , -125. );
            glVertex2f(50. , -175. );
            glVertex2f(0. , -150. );
            glVertex2f(-50. , -175. );
            glVertex2f(-50. , -125. );
    glEnd();

    /** Kotak paling dalam **/

    //glColor3f(0.643, 0.204, 0.749);
    //glColor3f(0.808,0.031,1);
    glBegin(GL_POLYGON); // PANAH 4// P4
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(0. , 0. );
            glVertex2f(-25. , 25. );
            glVertex2f(0. , 50. );
            glVertex2f(25. , 25. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 4// P4
            glColor3f(0.808,0.031,1);
            glVertex2f(-50. , 0. );
            glVertex2f(-25. , -25. );
            glVertex2f(0. , 0. );
            glVertex2f(-25. , 25. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 4// P4
            glColor3f(0.643, 0.204, 0.749);
            glVertex2f(0. , 0. );
            glVertex2f(-25. , -25. );
            glVertex2f(0. , -50. );
            glVertex2f(25. , -25. );
    glEnd();

    glBegin(GL_POLYGON); // PANAH 4// P4
            glColor3f(0.808,0.031,1);
            glVertex2f(50. , 0. );
            glVertex2f(25. , -25. );
            glVertex2f(0. , 0. );
            glVertex2f(25. , 25. );
    glEnd();

}

void display(void){
    glClear(GL_COLOR_BUFFER_BIT);
    userdraw();
    glutSwapBuffers();
}

int main(int argc, char * argv[]) {
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowPosition(0,0);
    glutInitWindowSize(500,500);
    glutCreateWindow("Tugas Pola Ubin");
    glClearColor( 0.945, 0.976, 0.82, 1.);
    gluOrtho2D(-500. , 500.  , -500. , 500.);
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

Comments

Popular posts from this blog

Quantization of Image Data Implementation in C#

Computer Graphics Project "Planet Orbit" Source Code with Glut OpenGL

Computer Graphics Project "MINION" Source Code with Glut OpenGL