Advertisement
Guest User

Untitled

a guest
Dec 8th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. // Spiral Thing
  2. // By: Chdata
  3. #include "stdafx.h"
  4. #include <iostream>
  5. #include <Windows.h>
  6. #include <glut.h>
  7.  
  8. #include <WinBase.h>
  9. #include <cstdlib>
  10. #include <ctime>
  11.  
  12. const int XSize = 640, YSize = XSize/4*3, winsize = XSize * YSize;
  13.  
  14. void circul(float xcenter, float ycenter, float a, float b, float r)
  15. {
  16. float pi = 3.1415926f;
  17. float dtr = pi/180.0f;
  18.     glBegin(GL_LINES);
  19.     glColor3f(rand()&1,rand()&1,rand()&1); //glColor3f(0.0f,0.0f,1.0f
  20.    
  21.     float x = xcenter + r * cos(a); //* pi/180.0f
  22.     float y = ycenter + r * -sin(a);
  23.  
  24.     for(a; a < b; a+=dtr)
  25.     {
  26.         glVertex2f(x,y);
  27.         x = xcenter + r * cos(a);
  28.         y = ycenter + r * -sin(a);
  29.         glVertex2f(x,y);
  30.     }
  31.     glEnd();
  32.     glutSwapBuffers();
  33. }
  34.  
  35. void display(void)
  36. {
  37.     float a = 0.0f;
  38.     float b = 0.03125f;
  39.     float e = 0.5f;
  40.     float f = e + b;
  41.     float g = 1.0f;
  42.     float h = g + b;
  43.     float j = 1.5f;
  44.     float k = j + b;
  45.     float step = b;
  46.     float pi = 3.1415926f;
  47.     float x = XSize/2;
  48.     float y = YSize/2;
  49.     float d = 0.0f;
  50.     float r = 191.0f;
  51.  
  52.     while (true)
  53.     {
  54.         while (d<r)
  55.         {
  56.             circul(x, y, a * pi, b * pi, d * 2);
  57.             circul(x, y, e * pi, f * pi, d * 2);
  58.             circul(x, y, g * pi, h * pi, d * 2);
  59.             circul(x, y, j * pi, k * pi, d * 2);
  60.             a += step;
  61.             b += step;
  62.             e += step;
  63.             f += step;
  64.             g += step;
  65.             h += step;
  66.             j += step;
  67.             k += step;
  68.             if (a>=2) a-=2;
  69.             if (b> 2) b-=2;
  70.             if (e>=2) e-=2;
  71.             if (f> 2) f-=2;
  72.             if (g>=2) g-=2;
  73.             if (h> 2) h-=2;
  74.             if (j>=2) j-=2;
  75.             if (k> 2) k-=2;
  76.             d++;
  77.             Sleep(182);
  78.         }
  79.  
  80.         if (d=r) d=0;
  81.         //Sleep(182);
  82.         //if (!d) glClear(GL_COLOR_BUFFER_BIT);
  83.     }
  84.  
  85.     /*
  86.     float a = 0.0f, b = 0.0f; //, r = 0.0f;
  87.     float x = XSize/2, y = YSize/2;
  88.     float pi = 3.1415926f;
  89.     float dtr = pi/180.0f;
  90.     for(float r = 0.0f; r < 192.0f; r++)
  91.     {
  92.         b += 1.875f;
  93.         circul(x, y, a, b * dtr, r);
  94.         glClear(GL_COLOR_BUFFER_BIT);
  95.     }
  96.     */
  97. }
  98.  
  99. void init(void)
  100. {
  101.     glMatrixMode (GL_PROJECTION);
  102.     glLoadIdentity (); 
  103.     glOrtho (0, XSize, YSize, 0, 0, 1);
  104.     glMatrixMode (GL_MODELVIEW);
  105. }
  106.  
  107. int _tmain(int argc, char **argv )
  108. {
  109.     srand((unsigned int)time(NULL));
  110.     glutInit(&argc, argv);
  111.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  112.     glutInitWindowSize(XSize, YSize);
  113.     glutCreateWindow("Brought to you by:");
  114.     glutDisplayFunc(display);
  115.     init();
  116.     glutMainLoop();
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement