Selasa, 04 Desember 2012

Membuat Bentuk Obat Nyamuk persegi 6 (spiral hexagon) di OpenGL



#include <gl/Gl.h>
#include <gl/glut.h>
#include <math.h>

void obat(){
     glClear(GL_COLOR_BUFFER_BIT);
     glBegin(GL_LINE_STRIP);
     glColor3f(0.0, 0.0, 1.0);
     double angle , angleInc, cx, cy, radius, rotAngle;
     int n=6;
     rotAngle=0;
     if(n < 3) return;
     angle = rotAngle* 3.14159265/180;
     angleInc= 2 * 3.14159265/n;
     for(int i = 0; i < 10; i++){
           for(int j = 0; j < n; j++){
                 angle += angleInc;
                 glVertex2f((radius+i) * cos(angle) + cx, (radius+i) * sin(angle) + cy);
           }
     }
     glEnd();
     glFlush();
}

main(int argc, char *argv[]){
         glutInit(&argc,argv);
         glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
         glutInitWindowSize(500,500);
         glutCreateWindow("Obat Nyamuk");
         glutDisplayFunc(obat);
         glClearColor(1.0,1.0,1.0,0.0);
         glPointSize(4.0);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluOrtho2D(-10.0,10.0,-11.0,11.0);
         glViewport(40, 400, 60, 300);  
         glutMainLoop();
}





silah kan download codingnya disini

Tidak ada komentar:

Posting Komentar