Advertisement
gurumutant

Animasi_deformasi_petals

Mar 8th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <GL/glut.h>
  4.  
  5. using namespace std;
  6.  
  7. typedef struct { float x,y; } titik_f;
  8.  
  9. void drawPoly (titik_f t[], int jmlKoordinat, bool closedLoop) {
  10.     int i;
  11.     (closedLoop) ? glBegin(GL_LINE_LOOP) : glBegin(GL_LINE_STRIP);
  12.     for (i=0;i<jmlKoordinat;i++) {
  13.         glVertex2f(t[i].x, t[i].y);
  14.     }
  15.     glEnd(); glFlush();
  16. }
  17.  
  18. void nggambar() {
  19.     static int tick=0;
  20.     titik_f P[360];
  21.     double srad, r;
  22.     for(int s=0;s<360;s++) {
  23.         srad=(s*tick)*3.14/180;
  24.         r=100*sin(5*srad);
  25.         P[s].x=(float)(r*cos(srad));
  26.         P[s].y=(float)(r*sin(srad));
  27.     }
  28.     drawPoly(P, 360, true);
  29.     tick++; Sleep(200);
  30. }
  31.  
  32. void tampil() {
  33.     glClear(GL_COLOR_BUFFER_BIT);
  34.     nggambar();
  35.     glutSwapBuffers();
  36. }
  37.  
  38. int main(int argc, char** argv)
  39. {
  40.     glutInit(&argc, argv);
  41.     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
  42.     glutInitWindowPosition(100,100);
  43.     glutInitWindowSize(640,480);
  44.     glutCreateWindow("Pemrograman Grafik RPL 2015");
  45.     // glClearColor(1.0,1.0,1.0,0);
  46.     gluOrtho2D(-100.,100.,-100.,100.);
  47.     glutIdleFunc(tampil);
  48.     glutDisplayFunc(tampil);
  49.     glutMainLoop();
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement