Advertisement
Mary_99

POLYGON_CORRECT

Mar 13th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.05 KB | None | 0 0
  1. #include "primlib.h"
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #define ANGLE_OF_ROTATION M_PI/80
  5. #define VERTICLES 5
  6. #define VALUE_OF_DEALY 20
  7.  
  8.  
  9. void DrawPolygon (double origin_x, double origin_y , int radious, double rotation)
  10. {
  11.     double start_x;
  12.     double start_y;
  13.  
  14.     double stop_x;
  15.     double stop_y;
  16.    
  17.     double polygonAngle = (2*M_PI)/ VERTICLES;
  18.     int i;
  19.    
  20.     for (i = 0; i < VERTICLES;  i++)
  21.     {
  22.         start_x = origin_x + radious * cos(polygonAngle* i + rotation);
  23.         start_y = origin_y + radious * sin(polygonAngle* i + rotation);
  24.         stop_x = origin_x + radious * cos(polygonAngle* (i + 1) + rotation);
  25.         stop_y = origin_y + radious * sin(polygonAngle* (i + 1) + rotation);
  26.  
  27.         line(start_x, start_y, stop_x , stop_y, BLUE);
  28.     }
  29. }
  30.  
  31. int min (int a, int b)
  32. {
  33.     if(a < b)
  34.         return a;
  35.     return b;
  36. }
  37. int main(int argc, char* argv[])
  38. {
  39.  
  40.     if(initGraph())
  41.     {
  42.  
  43.         exit(3);
  44.     }
  45.    
  46.  
  47.     int radious = 10;
  48.     int anlargment = 20;
  49.     double rotation = 0 ;
  50.    
  51.    
  52.  
  53.     double origin_x = screenWidth() / 2;
  54.     double origin_y = screenHeight() / 2;
  55.  
  56.    
  57.     while(1)
  58.     {
  59.        
  60.         filledRect(0, 0, screenWidth() - 1, screenHeight() - 1, BLACK);
  61.  
  62.         int maxRadious = (int)(min(screenWidth(), screenHeight())/2);
  63.         anlargment = (anlargment + 1) % (2 * maxRadious);
  64.         if (anlargment < maxRadious)
  65.         {
  66.             radious = anlargment;
  67.         }
  68.         else
  69.         {
  70.             radious = maxRadious - anlargment % maxRadious;
  71.         }
  72.        
  73.         if (rotation + ANGLE_OF_ROTATION >= 2* M_PI)
  74.         {
  75.             rotation -= 2*M_PI;
  76.         }
  77.        
  78.        
  79.         rotation += ANGLE_OF_ROTATION;
  80.  
  81.  
  82.         DrawPolygon( origin_x, origin_y , radious, rotation);
  83.  
  84.         updateScreen();
  85.         SDL_Delay(VALUE_OF_DEALY);
  86.  
  87.  
  88.  
  89.         if (isKeyDown(SDLK_ESCAPE) == 1)
  90.         {
  91.             break;
  92.         }
  93.  
  94.        
  95.     }
  96.     updateScreen();
  97.     SDL_Delay(VALUE_OF_DEALY);
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement