You are on page 1of 8

NAMA : ROY BELMIRO VIRGIANT

NIM : 17051204016
KELAS : TI 2017 A
TUGAS MODUL 5 – STRUCT
SourceCode :

// MODUL5_Struct.cpp : This file contains the 'main' function. Program execution begins
and ends there.
//

#include <GL/glut.h>
#include <math.h>

typedef struct {
float r;
float g;
float b;
} color_t;

typedef struct
{
float x, y;
} Point2D_t;

void setColor(color_t col)


{
glColor3f(col.r, col.g, col.b);
}

void drawPolyline(Point2D_t pnt[], int n)


{
int i;
glBegin(GL_LINE_LOOP);

for (i = 0; i < n; i++) {


glVertex2f(pnt[i].x, pnt[i].y);
}
glEnd();
}

void fillPolygon(Point2D_t pnt[], int n, color_t color)


{
int i;
setColor(color);
glBegin(GL_POLYGON);
for (i = 0; i < n; i++) {
glVertex2f(pnt[i].x, pnt[i].y);
}
glEnd();
}
void userdraw()
{
Point2D_t kananatas[6] = { {0,0},{100,100},{200,160}, {230, 120}, {220,10},{100,-
50} };
Point2D_t kananbawah[6] = { {0,0},{100,-50},{130,-100},{120,-200},{30,-160},{10,-
100} };
Point2D_t aksen1[3] = { {100,100},{200,160},{230,120} };
Point2D_t aksen2[3] = { { 0,0 }, { 100,100 }, { 230,120 } };
Point2D_t aksen3[3] = { { 0,0 }, {220, 10}, {100,-50} };
Point2D_t aksen4[3] = { {230,120},{220,10},{100,-50} };
Point2D_t aksen5[5] = { {0,0},{130,-100},{120,-200},{30,-160},{10,-100} };
Point2D_t aksen6[3] = { {100,-50},{130,-100},{10,-100} };
Point2D_t aksen7[3] = { {100,-50},{120,-200},{30,-160} };

Point2D_t kiriatas[6] = { {0,0},{-100,100},{-200,160}, {-230, 120}, {-220,10},{-


100,-50} };
Point2D_t kiribawah[6] = { {-0,0},{-100,-50},{-130,-100},{-120,-200},{-30,-160},{-
10,-100} };
Point2D_t aksen1k[3] = { {-100,100},{-200,160},{-230,120} };
Point2D_t aksen2k[3] = { { 0,0 }, { -100,100 }, { -230,120 } };
Point2D_t aksen3k[3] = { { 0,0 }, {-220, 10}, {-100,-50} };
Point2D_t aksen4k[3] = { {-230,120},{-220,10},{-100,-50} };
Point2D_t aksen5k[5] = { {0,0},{-130,-100},{-120,-200},{-30,-160},{-10,-100} };
Point2D_t aksen6k[3] = { {-100,-50},{-130,-100},{-10,-100} };
Point2D_t aksen7k[3] = { {-100,-50},{-120,-200},{-30,-160} };
Point2D_t backkanan[4] = { {0,-270},{0,270},{270,270},{270,-270} };
Point2D_t backkiri[4] = { {0,-270},{0,270},{-270,270},{-270,-270} };

color_t color1 = { 0.675, 0.302, 0.702 };


color_t color2 = { 0.728, 0.404, 0.755 };
color_t color3 = { 0.551, 0.288, 0.533 };
color_t color4 = { 0.728, 0.404, 0.755 };
color_t color5 = { 0.475, 0.004, 0.555 };
color_t color6 = { 0.662, 0.146, 1.093 };
color_t color7 = { 0.631, 0.777, 1.066 };
color_t color8 = { 0.511, 0.573, 0.8 };//sungu
color_t color9 = { 0.662, 0.146, 1.093 };//sungu
color_t color10 = { 1.133, 1.017, 0.8 };//badan
color_t color11 = { 0.986, 0.817, 0.6 };//badan

setColor(color10);
fillPolygon(backkanan, 4, color10);

setColor(color11);
fillPolygon(backkiri, 4, color11);

setColor(color1);
fillPolygon(kananatas, 6, color1);

setColor(color2);
fillPolygon(aksen1, 3, color2);

setColor(color3);
fillPolygon(aksen2, 3, color3);
setColor(color2);
fillPolygon(aksen3, 3, color2);

setColor(color5);
fillPolygon(aksen4, 3, color5);

//bwh
setColor(color5);
fillPolygon(kananbawah, 6, color5);

setColor(color1);
fillPolygon(aksen5, 5, color1);

setColor(color6);
fillPolygon(aksen6, 3, color6);

setColor(color2);
fillPolygon(aksen7, 3, color2);
//kirimang
setColor(color1);
fillPolygon(kiriatas, 6, color1);

setColor(color2);
fillPolygon(aksen1k, 3, color2);

setColor(color3);
fillPolygon(aksen2k, 3, color3);

setColor(color2);
fillPolygon(aksen3k, 3, color2);

setColor(color5);
fillPolygon(aksen4k, 3, color5);

//bwh
setColor(color5);
fillPolygon(kiribawah, 6, color5);

setColor(color1);
fillPolygon(aksen5k, 5, color1);

setColor(color6);
fillPolygon(aksen6k, 3, color6);

setColor(color2);
fillPolygon(aksen7k, 3, color2);

//setColor(hitam);
//drawPolyline(segitiga, 3);
}

void display(void)
{
//clear screen
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glutSwapBuffers();
}

int main(int argc, char** argv)


{
glutInit(&argc, argv);//Inisialisasi Toolkit
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100, 100); //membuat window dengan posisi 100x100
glutInitWindowSize(640, 480);//membuat window dengan ukuran 640x480
glutCreateWindow("MODUL 5 1st STRUCT"); //judul window
//glClearColor(1.0,1.0,1.0,0.0); //warna 1,1,1 adalah warna putih
glClearColor(1, 1, 1, 0);
//gluOrtho2D(-200.,200.,-200.,200.);//Mendefinisikan besarnya sistem koordinat
dengan range sumbu x
//adalah [0,640] dan range untuk
sumbu y adalah [-240,240]
gluOrtho2D(-270, 270, -270, 270);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Hasil :
NAMA : ROY BELMIRO VIRGIANT
NIM : 17051204016
KELAS : TI 2017 A
TUGAS MODUL 5 – STRUCT
SourceCode :

#include <GL/glut.h>
#include <math.h>

typedef struct {
float r;
float g;
float b;
} color_t;

typedef struct
{
float x, y;
} Point2D_t;

void setColor(color_t col)


{
glColor3f(col.r, col.g, col.b);
}

void gradatePolygon(Point2D_t pnt[], int n, color_t color[])


{
int i;

glBegin(GL_POLYGON);
for (i = 0; i < n; i++) {
setColor(color[i]);
glVertex2f(pnt[i].x, pnt[i].y);
}
glEnd();
}

void userdraw()
{
Point2D_t backkanan[4] = { {0,-270},{0,270},{270,270},{270,-270} };
Point2D_t backkiri[4] = { {0,-270},{0,270},{-270,270},{-270,-270} };
Point2D_t kanan[6] = { {0,0}, {42,50}, {100,50}, {142, 0}, {142,-95}, {0,-200} };
Point2D_t kiri[6] = { {0,0}, {-42,50}, {-100,50}, {-142, 0}, {-142,-95}, {0,-200}
};
color_t gradasibkan[4] = { { 0.511, 0.573, 0.8 }, {0.511, 0.573, 0.8 }, { 0.662,
0.146, 1.093 }, { 0.662, 0.146, 1.093 } };
color_t gradasibkir[4] = { { 0.662, 0.146, 1.093 }, { 0.662, 0.146, 1.093 },{
0.511, 0.573, 0.8 }, {0.511, 0.573, 0.8 } };
color_t grakanan[6] = {{ 1.133, 1.017, 0.8 },{ 0.675, 0.302, 0.702 },{ 0.675,
0.302, 0.702 },{ 0.675, 0.302, 0.702 },{ 0.675, 0.302, 0.702 },{ 1.133, 1.017, 0.8 } };
color_t grakiri[6] = { { 0.675, 0.302, 0.702 }, { 1.133, 1.017, 0.8 }, { 1.133,
1.017, 0.8 }, { 1.133, 1.017, 0.8 }, { 1.133, 1.017, 0.8 } ,{ 0.675, 0.302, 0.702 } };

gradatePolygon(backkanan, 4, gradasibkan);
gradatePolygon(backkiri, 4, gradasibkir);
gradatePolygon(kanan, 6, grakanan);
gradatePolygon(kiri, 6, grakiri);
}

void display(void)
{
//clear screen
glClear(GL_COLOR_BUFFER_BIT);
userdraw();
glutSwapBuffers();
}

int main(int argc, char** argv)


{
glutInit(&argc, argv);//Inisialisasi Toolkit
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100, 100); //membuat window dengan posisi 100x100
glutInitWindowSize(640, 480);//membuat window dengan ukuran 640x480
glutCreateWindow("MODUL 5 Gradasi"); //judul window
//glClearColor(1.0,1.0,1.0,0.0); //warna 1,1,1 adalah warna putih
glClearColor(1, 1, 1, 0);
//gluOrtho2D(-200.,200.,-200.,200.);//Mendefinisikan besarnya sistem koordinat
dengan range sumbu x
//adalah [0,640] dan range untuk
sumbu y adalah [-240,240]
gluOrtho2D(-270,270,-270,270);
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Hasil :

You might also like