Advertisement
Mary_99

polygon try 1

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