Pages

Tuesday, 24 April 2012

Latihan OpenGL (2)

 Latihan Kedua Semoa Bermanfaat ....


#include <glut.h>
#include <windows.h>=
#include <stdio.h>
#include <math.h>
const double PI = 3.141592653589793;
int i,j,s,t,radius,jumlah_titik,x_tengah,y_tengah;
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
//1
radius=8;
jumlah_titik=40;
x_tengah=-87;
y_tengah=87;


for (j=1;j<=64;j++)
{
s=s+1;
t=t+1;
if (t==4){t=1;}
if (s==9){s=1;
y_tengah-=25;x_tengah=-87;}

if(t==1) {glColor3f(0.,1.,0.);}
if(t==2) {glColor3f(0.,0.,1.);}
if(t==3) {glColor3f(1.,1.,0.);}

glBegin(GL_LINE_LOOP);
for (i=0;i<=360;i++){
float sudut=i*(2*PI/jumlah_titik);
float x=x_tengah+radius*cos(sudut);
float y=y_tengah+radius*sin(sudut);
glVertex2f(x/100,y/100);
}
x_tengah+=25;
glEnd();

}
glPopMatrix();
float x,y;
glBegin(GL_LINES);
x=-1;
y=1;
for (i=1;i<=9;i++)
{
glVertex2f(x,1);
glVertex2f(x,-1);
//vertikal
glVertex2f(-1,y);
glVertex2f(1,y);

y-=0.25;
x+=0.25;
}

glEnd();
glutSwapBuffers();
glFlush ( );
}
void main (int argc, char** argv){
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (0, 0);
glutInitWindowSize(1000, 600);
glutCreateWindow("Latihan 2" );
glutDisplayFunc(Draw);
glutMainLoop();
}

2 comments:

Amirul Ikhsan said...

Mantep mas, coba contoh yang lainnya ...
heheh :)

Basoeky said...

Heheheheheeee
ntar di usahain ya ....

Post a Comment