Advertisement
filiz

Untitled

Jan 23rd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. #define PI 3.14159265
  8.  
  9. void drawHex(int lines, int radius, int *centerCoordinates, int color, bool filled = false, double angle = 0, bool isCircle = false)
  10. {
  11. int points[lines * 2]= {0};
  12. int n = lines, R = radius, Xc=(*centerCoordinates++), Yc=(*centerCoordinates);
  13. for(int i=0; i<n; i++)
  14. {
  15. double alfa = i * 2 * PI/n + angle;
  16. points[2*i] = Xc + R * cos(alfa);
  17. points[2*i+1] = Yc + R * sin(alfa);
  18. }
  19. points[lines * 2] = points[0];
  20. points[lines * 2 +1] = points[1];
  21. setcolor(color);
  22. if(filled)
  23. {
  24. fillpoly(lines+1,points);
  25. }
  26. drawpoly(lines+1,points);
  27. }
  28.  
  29. int main()
  30. {
  31. initwindow(500, 250);
  32. setcolor(RED);
  33. int centerCoordinates[2] = {getmaxx()/2, getmaxy()/2};
  34. int i = 1, radius = 30;
  35. double a=0;
  36. while(true)
  37. {
  38. if(kbhit())
  39. {
  40. int c = getch();
  41. if (c == '+')
  42. a+=0.1;
  43. else if(c == '-' && radius != 0)
  44. {
  45. a-=0.1;
  46. }
  47.  
  48.  
  49. }
  50. drawHex(4, radius, centerCoordinates, RED, true, a, true);
  51. cleardevice();
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement