Grafkom Membuat 3 Bintang

Tutorial Grafkom Membuat 3 Bintang - Tutorial selanjutnya pemrograman Grafika Komputer yaitu membuat 3 Bintang. Bagi rekan-rekan yang sekarang menempuh mata kuliah Grafika Komputer mungkin bisa mencoba script dibawah ini dan bisa dijadikan referensi.

Script Code : 
# include <glut.h>
# include <stdio.h>
# include <stdlib.h>
typedef struct {
float x,y;
} point2D_t;
typedef struct{
float x,y,z;
}
color_t;
void setColor(color_t color)
{
glColor3f(color.x, color.y,color.z);
}
void fillPolygonGradate(point2D_t a[],int n,color_t color[])
{
int i;
glBegin(GL_POLYGON);
for(i=0;i<n;i++)
{
int w=i/2;
//int w=i;
setColor(color[w]);
glVertex2f(a[i].x,a[i].y);
}
glEnd();
}
void userDraw(void)
{
point2D_t bintang1[10]={{240,150},{350,230},{215,230},{240,310},{265,230},{140,230},{270,230},{300,100},{200,180},{180,100}};
color_t wrnbintang1[10]={{1.,1.,0.},{1.,1.,0.},{0.,1.,1},{1.,1.,0.},{0.,1.,1},{1.,1.,1.}};
point2D_t bintang2[10]={{110,290},{187,350},{93,350},{110,400},{129,350},{33,350},{140,315},{158,260},{84,315},{62,260}};
color_t wrnbintang2[10]={{1.,0.,1.},{1.,1.,1.},{1.,0.,1.},{1.,1.,1.},{1.,0.,1.},{1.,1.,1.}};
point2D_t bintang3[10]={{380,290},{457,350},{363,350},{380,400},{399,350},{303,350},{410,315},{428,260},{354,315},{332,260}};
color_t wrnbintang3[10]={{1.,1.,1.},{0.,1.,1.},{0.,1.,1.},{0.,1.,1.},{0.,1.,1.},{0.,1.,1.}};
fillPolygonGradate(bintang1,10,wrnbintang1);
fillPolygonGradate(bintang2,10,wrnbintang2);
fillPolygonGradate(bintang3,10,wrnbintang3);
}
void display (void)
{
userDraw();
glFlush();
}
void main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(100,150);
glutInitWindowSize(500,500);
glutCreateWindow("Gradasi Warna");
glClearColor(1.0,1.0,1.0,0.0);
gluOrtho2D(0.,500.,0.0,500.0);
glutDisplayFunc(display);
glutMainLoop();
}
Oke selamat mencoba dan selamat Belajar.

2 komentar

mantaff gan...
izin cb..


mmpir...
http://pcomtricks.blogspot.com

Berkomentar yang sopan ya, Terimakasih sahabat..
EmoticonEmoticon