Advertisement
Mary_99

polygon try 2

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