#include
#include
#include
#include
int xb[200], yb[200], p;
#ifndef M_PI
#define M_PI 3.141592653589793
#endif
//fungsi untuk membuat bumi
// ------------------------------------
// Struktur Data Untuk Keperluan Grafis
// ------------------------------------
typedef struct {
float v[3];
} vektor2D_t;
typedef struct {
float m[3][3];
} matrik2D_t;
typedef struct {
float x,y;
} titik2D_t;
typedef struct {
float r,g,b;
} warna_t;
// --------------
// Operasi Matrik
// --------------
matrik2D_t BuatMatrikIdentitas()
{
int i,j;
matrik2D_t I;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
I.m[i][j]=0.;
I.m[i][i]=1.;
}
return I;
}
matrik2D_t Translasi(float tambahx, float tambahy)
{
matrik2D_t a;
a=BuatMatrikIdentitas();
a.m[0][2]=tambahx;
a.m[1][2]=tambahy;
return a;
}
matrik2D_t Scaling(float rx,float ry)
{
matrik2D_t a;
a=BuatMatrikIdentitas();
a.m[0][0]=rx;
a.m[1][1]=ry;
return a;
}
matrik2D_t Rotasi(float sudut)
{
matrik2D_t a;
a=BuatMatrikIdentitas();
a.m[0][0]=cos(sudut); a.m[0][1]=-sin(sudut);
a.m[1][0]=sin(sudut); a.m[1][1]=cos(sudut);
return a;
}
matrik2D_t operator * (matrik2D_t a, matrik2D_t b)
{
matrik2D_t c;//c=a*b
int i,j,k;
for (i=0;i<3;i++) for (j=0;j<3;j++) {
c.m[i][j]=0;
for (k=0;k<3;k++) c.m[i][j]+=a.m[i][k]*b.m[k][j];
}
return c;
}
vektor2D_t operator * (matrik2D_t a, vektor2D_t b)
{
vektor2D_t c;//c=a*b
int i,j;
for (i=0;i<3;i++) {
c.v[i]=0;
for (j=0;j<3;j++) c.v[i]+=a.m[i][j]*b.v[j];
}
return c;
}
// ------------------------
// Pemindahan Struktur Data
// ------------------------
vektor2D_t titik2vektor (titik2D_t a)
{
vektor2D_t b;
b.v[0]=a.x;
b.v[1]=a.y;
b.v[2]=1.;
return b;
}
titik2D_t vektor2titik (vektor2D_t a)
{
titik2D_t b;
b.x=a.v[0];
b.y=a.v[1];
return b;
}
// ------------------------------
// Fungsi-fungsi untuk menggambar
// ------------------------------
void setwarna(warna_t a)
{
glColor3f(a.r,a.g,a.b);
}
void drawTitik(titik2D_t a)
{
glBegin(GL_POINTS);
glVertex2f(a.x,a.y);
glEnd();
}
void drawGaris(float x1,float y1, float x2, float y2)
{
glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();
}
void drawGaris(titik2D_t a,titik2D_t b)
{
glBegin(GL_LINES);
glVertex2f(a.x,a.y);
glVertex2f(b.x,b.y);
glEnd();
}
void drawPolyLine(titik2D_t a[],int n)
{
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i
glEnd();
}
void drawPolyLineColor(titik2D_t a[],warna_t w[],int n)
{
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i
glColor3f(w[i].r,w[i].g,w[i].b);
glVertex2f(a[i].x,a[i].y);
}
glEnd();
}
void drawPolygon(titik2D_t a[],int n)
{
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i
glVertex2f(a[0].x,a[0].y);
glEnd();
}
void drawPolygonColor(titik2D_t a[],warna_t w[],int n)
{
int i;
glBegin(GL_LINE_STRIP);
for(i=0;i
glColor3f(w[i].r,w[i].g,w[i].b);
glVertex2f(a[i].x,a[i].y);
}
glVertex2f(a[0].x,a[0].y);
glEnd();
}
void fillPolygon(titik2D_t a[],warna_t w,int n)
{
int i;
setwarna(w);
glBegin(GL_POLYGON);
for(i=0;i
glEnd();
}
void gradatePolygon(titik2D_t a[],warna_t w[],int n)
{
int i;
glBegin(GL_POLYGON);
for(i=0;i
glColor3f(w[i].r,w[i].g,w[i].b);
glVertex2f(a[i].x,a[i].y);
}
glEnd();
}
titik2D_t interpolasi(titik2D_t a,titik2D_t b, float m)
{
titik2D_t c;
c.x=m*a.x+(1.-m)*b.x;
c.y=m*a.y+(1.-m)*b.y;
return c;
}
titik2D_t Translasi(titik2D_t p, float dx,float dy){
titik2D_t q;
q.x=p.x+dx;
q.y=p.y+dy;
return q;
}
titik2D_t Scaling(titik2D_t p, float ax,float ay){
titik2D_t q;
q.x=ax*p.x;
q.y=ay*p.y;
return q;
}
titik2D_t Rotasi(titik2D_t p, float teta){
titik2D_t q;
q.x=p.x*cos(teta)-p.y*sin(teta);
q.y=p.x*sin(teta)+p.y*cos(teta);
return q;
}
void userdraw(void)
{
static int tick=0;
int k,stick;
double sc;
titik2D_t daun[360],daun1[360],
daun2[360];
titik2D_t balon[30],balon1[30],balon2[30],balon3[30],balon4[30],
balon5[30],balon6[30];
// titik2D_t alis1[30],alis2[30];
warna_t w0={0.90,0.75,0.};
warna_t w1={0.85,0.75,0.};
warna_t w2={1.,1.,1.};
warna_t w3={0.,0.,0.};
warna_t coklat1={0.7,0.6,0.5};
warna_t coklat3={0.1,1.0,1.0};
warna_t coklat={0,0,0};
warna_t orange={1,0.50,0};
warna_t merah={1,0.75,0};
warna_t abu2={0.,0.7,0.0};
warna_t abu1={0.4,0.6,0.1};
warna_t abu3={0.7,0.5,0.8};
warna_t biru={0,0.6,0.3};
warna_t coklat2={0.5,0.4,0.3};
for(k=0;k<360;k++)
{
sc=k*M_PI/180.;
//daun
daun[k].x=220.+100*cos(sc)+12*rand()/RAND_MAX-8.;
daun[k].y=-380+190.*sin(sc)+10.*rand()/RAND_MAX;
daun2[k].x=130.+150*cos(sc)+12*rand()/RAND_MAX-8.;
daun2[k].y=-380+190.*sin(sc)+10.*rand()/RAND_MAX;
daun1[k].x=-170.+200*cos(sc)+16*rand()/RAND_MAX-8.;
daun1[k].y=-380+250.*sin(sc)+15.*rand()/RAND_MAX-4;
}
stick=tick%12-5;
if(stick<1) stick=0;
for(k=0;k<30;k++)
{
sc=12.*k*M_PI/180.;
//kupu kupu
balon[k].x=-200.+12.5*cos(sc);
balon[k].y=0.+(8.5-stick)*sin(sc);
balon[k]=Rotasi (balon[k],30*3.14/180);
balon3[k].x=-190.+15*cos(sc);
balon3[k].y=0.+(7.5-stick)*sin(sc);
balon3[k]=Rotasi (balon3[k],30*3.14/180);
balon1[k].x=-200.+12.5*cos(sc);
balon1[k].y=-6.+(6-stick)*sin(sc);
balon1[k]=Rotasi (balon1[k],30*3.14/180);
balon4[k].x=-190.+12.5*cos(sc);
balon4[k].y=-6.+(8.5-stick)*sin(sc);
balon4[k]=Rotasi (balon4[k],30*3.14/180);
balon2[k].x=-195.+20*cos(sc);
balon2[k].y=-4.+2.5*sin(sc);
balon2[k]=Rotasi (balon2[k],30*3.14/180);
//hidung kupu-kupu
balon5[k].x=-175.+11*cos(sc);
balon5[k].y=-7+1*sin(sc);
balon5[k]=Rotasi (balon5[k],30*3.14/191.5);
balon6[k].x=-175.+10*cos(sc);
balon6[k].y=-7.5+1*sin(sc);
balon6[k]=Rotasi (balon6[k],30*3.14/185);
}
fillPolygon(daun,abu1,360);
fillPolygon(daun1,abu1,360);
fillPolygon(daun2,abu1,360);
// fillPolygon(laut,w3,360);
fillPolygon(balon5,abu2,30);
fillPolygon(balon6,abu2,30);
fillPolygon(balon3,orange,30);
fillPolygon(balon4,orange,30);
fillPolygon(balon,w0,30);
fillPolygon(balon1,w0,30);
fillPolygon(balon2,abu2,30);
tick++;
}
void display(void)
{
glClear( GL_COLOR_BUFFER_BIT);
userdraw();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowPosition(100,100);
glutInitWindowSize(480,480);
glutCreateWindow ("D4 / IT");
glClearColor(0.0, 0.6, 0.8, 0.0);
gluOrtho2D(-240., 240., -240.0, 240.0);
// Define the dimensions of the Orthographic Viewing Volume
glutIdleFunc(display); // idle event call back
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
1 komentar:
zzzzzzzzzzzzzzzzzzz......
Posting Komentar