SHARE
TWEET

GRADED POLYGON

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