Advertisement
Guest User

Untitled

a guest
Jan 15th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <cmath>
  4. #define PI 3.1415
  5. #define N 5
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.  
  12. initwindow(800,600);
  13. int points[]={220,150,320,150,320,250,220,250,220,150};
  14. int poligon[128];
  15. drawpoly(5,points);
  16. delay(2000);
  17. cleardevice();
  18. int points1[]={420,350,520,350,520,450,420,450,420,350};
  19. drawpoly(5,points1);
  20. delay(2000);
  21. cleardevice();
  22. double xc=0, yc=0;
  23. double hc=0,jc=0;
  24. for(int i=0;i<N;i++){
  25. xc += points1[2*i];
  26. yc += points1[2*i+1];
  27. }
  28. xc/=N;yc/=N;
  29. double cosa = cos(PI/4), sina = sin(PI/4);
  30. for(int i=0;i<N+1;i++){
  31. double xi,yi;
  32. xi = points1[2*i];
  33. yi = points1[2*i+1];
  34. points1[2*i] = xc + (xi-xc)*cosa - (yi-yc)*sina;
  35. points1[2*i+1] = yc + (xi-xc)*sina + (yi-yc)*cosa;
  36. }
  37.  
  38.  
  39. for(int i=0;i<2*N+2;i++) poligon[i]=(int)points1[i];
  40. setcolor(YELLOW);
  41. drawpoly(N+1,poligon);
  42. delay(3000);
  43. float Sx=1.2, Sy=1.2;
  44. float scal = 0.2;
  45. for(int i=0;i<N;i++){
  46. hc += points[2*i];
  47. jc += points[2*i+1];
  48. }
  49. hc/=N;jc/=N;
  50. while(1)
  51. {
  52. // scalare Sx,Sy
  53. for(int i=0;i<N;i++){
  54. points[2*i] = hc + (int)((points[2*i] - hc)*Sx);
  55. points[2*i+1]= jc + (int)((points[2*i+1]- jc)*Sy);
  56. }
  57. setcolor(GREEN);
  58. drawpoly(N,points);
  59. char c=getch();
  60. setcolor(BLACK);
  61. drawpoly(N,points);
  62.  
  63. switch(c){
  64. case 27 : return 0;
  65. case '+': Sx=Sx+1;Sy=Sy+1;break;
  66. case '-': Sx=Sx-1;Sy=Sy-1;break;
  67. case ' ': Sx=Sx+scal;Sy=Sy+scal;
  68. default: break;
  69. }
  70. if( (Sx<0.4) || (Sy>4))scal = -scal;
  71. }
  72.  
  73. closegraph;
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement