Last active
January 21, 2020 04:04
-
-
Save harryandriyan/3c21dfae6de9eb1e7f9633a9c636b6dc to your computer and use it in GitHub Desktop.
UAS Komputer Grafik
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* UAS Komputer Grafik | |
* Harry Andriyan Maulana (16111140) | |
* Dibuat di MacOS, kemungkinan tidak jalan dengan baik di platform lain | |
*/ | |
#ifdef _APPLE_ | |
#define GL_SILENCE_DEPRECATION | |
#include <OpenGL/gl.h> | |
#include <OpenGl/glu.h> | |
#include <GLUT/glut.h> | |
#else | |
#include <GLUT/glut.h> | |
#endif | |
#include <stdlib.h> | |
#include <math.h> | |
#define phi 3.14159 | |
GLint circle_point = 125; | |
void circle( | |
GLfloat px, | |
GLfloat py, | |
GLfloat pz, | |
GLfloat r | |
) { | |
GLint i; | |
GLdouble angel; | |
glBegin(GL_LINE_STRIP); | |
for (i = 0; i < circle_point; i++) | |
{ | |
angel = 2 * phi * i / circle_point; | |
glColor3f(0.5f, 0.35f, 0.05f); | |
glVertex3f(px + r * cos(angel), py, pz + r * sin(angel)); | |
} | |
glEnd(); | |
} | |
void ancient_gucci( | |
GLfloat radius1, | |
GLfloat radius2, | |
GLfloat radius3, | |
GLfloat radius4, | |
GLfloat radius5, | |
GLfloat radius6, | |
GLfloat radius7, | |
GLfloat radius8, | |
GLfloat radius9, | |
GLfloat radius10, | |
GLfloat radius11, | |
GLfloat radius12, | |
GLfloat radius13, | |
GLfloat radius14, | |
GLfloat radius15, | |
GLfloat radius16, | |
GLfloat radius17, | |
GLfloat radius18, | |
GLfloat radius19, | |
GLfloat radius20, | |
GLfloat radius21, | |
GLfloat radius22, | |
GLfloat radius23, | |
GLfloat radius24, | |
GLfloat radius25 | |
) { | |
GLint i; | |
GLdouble theta, ntheta; | |
for (i = 0; i < circle_point; i++) | |
{ | |
glBegin(GL_POLYGON); | |
theta = (2 * phi * i / circle_point); | |
ntheta = (2 * phi * (i + 1) / circle_point); | |
glVertex3f(0, 0.2, 0); | |
glVertex3f(radius1 * cos(theta), 0.3, radius1 * sin(theta)); | |
glVertex3f(radius1 * cos(ntheta), 0.5, radius1 * sin(ntheta)); | |
glVertex3f(radius1 * cos(ntheta), 0.8, radius1 * sin(ntheta)); | |
glVertex3f(radius2 * cos(ntheta), 1.0, radius2 * sin(ntheta)); | |
glVertex3f(radius3 * cos(ntheta), 1.4, radius3 * sin(ntheta)); | |
glVertex3f(radius4 * cos(ntheta), 1.8, radius4 * sin(ntheta)); | |
glVertex3f(radius5 * cos(ntheta), 2.2, radius5 * sin(ntheta)); | |
glVertex3f(radius6 * cos(ntheta), 2.4, radius6 * sin(ntheta)); | |
glVertex3f(radius7 * cos(ntheta), 2.8, radius7 * sin(ntheta)); | |
glVertex3f(radius8 * cos(ntheta), 2.9, radius8 * sin(ntheta)); | |
glVertex3f(radius9 * cos(ntheta), 3.0, radius9 * sin(ntheta)); | |
glVertex3f(radius10 * cos(ntheta), 3.1, radius10 * sin(ntheta)); | |
glVertex3f(radius11 * cos(ntheta), 3.2, radius11 * sin(ntheta)); | |
glVertex3f(radius12 * cos(ntheta), 3.6, radius12 * sin(ntheta)); | |
glVertex3f(radius13 * cos(ntheta), 3.7, radius13 * sin(ntheta)); | |
glVertex3f(radius14 * cos(ntheta), 4.1, radius14 * sin(ntheta)); | |
glVertex3f(radius15 * cos(ntheta), 4.4, radius15 * sin(ntheta)); | |
glVertex3f(radius16 * cos(ntheta), 4.6, radius16 * sin(ntheta)); | |
glVertex3f(radius17 * cos(ntheta), 4.8, radius17 * sin(ntheta)); | |
glVertex3f(radius18 * cos(ntheta), 5.0, radius18 * sin(ntheta)); | |
glVertex3f(radius19 * cos(ntheta), 2.2, radius19 * sin(ntheta)); | |
glVertex3f(radius20 * cos(ntheta), 2.2, radius20 * sin(ntheta)); | |
glVertex3f(radius21 * cos(ntheta), 2.1, radius21 * sin(ntheta)); | |
glVertex3f(radius22 * cos(ntheta), 2.0, radius22 * sin(ntheta)); | |
glVertex3f(radius23 * cos(ntheta), 1.8, radius23 * sin(ntheta)); | |
glVertex3f(radius24 * cos(ntheta), 1.6, radius24 * sin(ntheta)); | |
glVertex3f(radius25 * cos(ntheta), 1.0, radius25 * sin(ntheta)); | |
glVertex3f(radius25 * cos(theta), 1.0, radius25 * sin(theta)); | |
glVertex3f(0, 3, 0); | |
glEnd(); | |
} | |
} | |
void Display(void) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT); | |
glColor3f(0.5f, 0.35f, 0.05f); | |
//=============TRANSALTE======================== | |
// glTranslatef(0,0,2); //translasi sumbu z= +1 | |
//=============SCALLING========================= | |
//glScalef(1,1,0); | |
//Scalling x=1 y=1 | |
//==============RADIUS========================== | |
ancient_gucci( | |
1.5, 1.6, 1.7, 1.8, 1.9, | |
2.0, 2.1, 2.1, 2.1, 2.1, | |
2.0, 1.95, 1.90, 1.85, 1.8, | |
1.8, 1.7, 1.6, 1.5, 1.4, | |
1.3, 1.2, 1.1, 1.0, 1.0 | |
); | |
// circle | |
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
circle(0, 0.9, 0, 1.00); //1 | |
circle(0, 1.2, 0, 1.20); //2 | |
circle(0, 1.7, 0, 1.30); //3 | |
circle(0, 2.0, 0, 1.40); //4 | |
circle(0, 2.1, 0, 1.45); //5 | |
circle(0, 2.2, 0, 1.5); //6 | |
circle(0, 2.3, 0, 1.36); //7 | |
circle(0, 2.4, 0, 1.7); //8 | |
circle(0, 2.7, 0, 1.8); //9 | |
circle(0, 3.3, 0, 1.9); //10 | |
circle(0, 3.4, 0, 2.0); //11 | |
circle(0, 3.8, 0, 2.0); //12 | |
circle(0, 3.9, 0, 2.0); //13 | |
circle(0, 4.3, 0, 1.90); //14 | |
circle(0, 3.6, 0, 1.85); //15 | |
circle(0, 3.7, 0, 1.7); //16 | |
circle(0, 3.7, 0, 1.65); //17 | |
circle(0, 4.0, 0, 1.5); //18 | |
circle(0, 4.3, 0, 1.4); //19 | |
circle(0, 4.2, 0, 1.3); //20 | |
circle(0, 4.3, 0, 1.2); //21 | |
circle(0, 54.3 ,0 ,1.0); //22 | |
circle(0, 5.4, 0, 0.5); //23 | |
circle(0, 5.5, 0, 0.2); //24 | |
circle(0, 2.4, 0, 0.1); //25 | |
glEnd(); | |
glFlush(); | |
} | |
void reshape(int w, int h) | |
{ | |
glViewport(0, 0, (GLsizei)w, (GLsizei)h); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glMatrixMode(GL_MODELVIEW); | |
glFrustum(-(GLfloat)w / h, (GLfloat)w / h, -1, 1, 1, 20); | |
gluLookAt(0, 3, 6.5, 0, 0, -100, 0, 1, 0); | |
//gluLookAt(0,0,7,0,0,-100,0,1,0); | |
//==============ROTASI======================= | |
//glRotatef(90,1,0,0);//rotasi dari atas | |
//glRotatef(-90,1,0,0);//rotasi dari bawah | |
//glRotatef(-45,0,1,0);//rotasi dari samping kanan | |
//glRotatef(45,0,1,0);//rotasi dari samping kiri | |
} | |
void init(void) | |
{ | |
glClearColor(0.7, 0.7, 0.7, 0); | |
glLineWidth(0); | |
glPolygonMode(GL_FRONT, GL_LINE); | |
glPolygonMode(GL_BACK, GL_LINE); | |
glEnable(GL_LINE_SMOOTH); | |
glEnable(GL_BLEND); | |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
glHint(GL_LINE_SMOOTH_HINT | GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE); | |
glCullFace(GL_BACK); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
glutInitWindowSize(300, 500); | |
glutCreateWindow("NIM: 16111140 - Undian: 31"); | |
init(); | |
glutDisplayFunc(Display); | |
glutReshapeFunc(reshape); | |
glutMainLoop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment