Xom9ik

SRS #2/20var (IV semester) CG

Jun 11th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "glut.h"
  3. #include <cmath>
  4. #include <iostream>
  5. #include <string>
  6. #include <ctime>
  7. #define SIZE 6
  8. #define LP 0.4
  9. #define M 3.14
  10. using namespace std;
  11.  
  12. # define M_PI           3.14159265358979323846  /* pi */
  13. GLint Width = 800, Height = 800;
  14.  
  15.  
  16. void DRAWING(double x, double y, double r, double a) {
  17.     double m1[SIZE];
  18.     double m2[SIZE];
  19.     glBegin(GL_LINES);
  20.     glLineWidth(2.0);
  21.     for (int i = 0; i < SIZE; i++) {
  22.         m1[i] = r * cos(a + i * M_PI*LP);
  23.         m2[i] = r * sin(a + i * M_PI*LP);
  24.     }
  25.     for (int i = 0; i < SIZE - 1; i++) {
  26.         glColor3d(0.0, 1.0, 0.0);
  27.         glVertex2d(x + m1[i], y + m2[i]);
  28.         glVertex2d(x + m1[i + 1], y + m2[i + 1]);
  29.     }
  30.     glEnd();
  31.     glFinish();
  32. }
  33. void DARER(double x, double y, double r, double a, int d) {
  34.     double v;
  35.  
  36.     v = 2 * r*cos(M_PI / 5);
  37.     for (int i = 0; i < SIZE; i++) {
  38.         DRAWING(x - v * cos(a + i * M_PI*LP), y - v * sin(a + i * M_PI*LP), r, a + M_PI + i * M_PI*LP);
  39.         if (d > 0)
  40.             DARER(x - v * cos(a + i * M_PI*LP), y -
  41.                 v * sin(a + i * M_PI*LP), r / (2 * cos(M_PI / 5) + 1), a + M_PI + (2 * i + 1)*M_PI * 2 / 10, d - 1);
  42.     }
  43. }
  44.  
  45. void Draw()
  46. {
  47.     DARER(100, 100, 95, M_PI / 10, 4);
  48. }
  49. void Reshape(GLint w, GLint h)
  50. {
  51.     glClearColor(0.3, 0.3, 0.3, 1.0);
  52.     glClear(GL_COLOR_BUFFER_BIT);
  53.     Width = w;
  54.     Height = h;
  55.     glViewport(0, 0, w, h);
  56. }
  57. void main(int argc, char ** argv)
  58. {
  59.     glutInit(&argc, argv);
  60.     glutInitDisplayMode(GLUT_RGB);
  61.     glutInitWindowPosition(200, 200);
  62.     glutInitWindowSize(Width, Height);
  63.     glutCreateWindow("Gosper's Curve");
  64.  
  65.     glClearColor(0.3, 0.3, 0.3, 1.0);
  66.     glClear(GL_COLOR_BUFFER_BIT);
  67.  
  68.     glutDisplayFunc(Draw);
  69.     glutReshapeFunc(Reshape);
  70.     glMatrixMode(GL_PROJECTION);
  71.  
  72.     glScaled(0.001f, 0.001f, 0.001f);
  73.  
  74.     glutMainLoop();
  75. }
Advertisement
Add Comment
Please, Sign In to add comment