gurumutant icon

Animasi_deformasi_petals

gurumutant | PRO | 03/08/17 05:46:01 AM UTC | 0 ⭐ | 553 👁️ | Never ⏰ | []
C++ |

1.19 KB

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <Windows.h>
#include <GL/glut.h>
 
using namespace std;
 
typedef struct { float x,y; } titik_f;
 
void drawPoly (titik_f t[], int jmlKoordinat, bool closedLoop) {
    int i;
    (closedLoop) ? glBegin(GL_LINE_LOOP) : glBegin(GL_LINE_STRIP);
    for (i=0;i<jmlKoordinat;i++) {
        glVertex2f(t[i].x, t[i].y);
    }
    glEnd(); glFlush();
}
 
void nggambar() {
    static int tick=0;
    titik_f P[360];
    double srad, r;
    for(int s=0;s<360;s++) {
        srad=(s*tick)*3.14/180;
        r=100*sin(5*srad);
        P[s].x=(float)(r*cos(srad));
        P[s].y=(float)(r*sin(srad));
    }
    drawPoly(P, 360, true);
    tick++; Sleep(200);
}
 
void tampil() {
    glClear(GL_COLOR_BUFFER_BIT);
    nggambar();
    glutSwapBuffers();
}
 
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    glutInitWindowPosition(100,100);
    glutInitWindowSize(640,480);
    glutCreateWindow("Pemrograman Grafik RPL 2015");
    // glClearColor(1.0,1.0,1.0,0);
    gluOrtho2D(-100.,100.,-100.,100.);
    glutIdleFunc(tampil);
    glutDisplayFunc(tampil);
    glutMainLoop();
    return 0;
}

Comments