Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <graphics.h>
- #include <cmath>
- #define PI 3.1415
- #define N 5
- using namespace std;
- int main()
- {
- initwindow(800,600);
- int points[]={220,150,320,150,320,250,220,250,220,150};
- int poligon[128];
- drawpoly(5,points);
- delay(2000);
- cleardevice();
- int points1[]={420,350,520,350,520,450,420,450,420,350};
- drawpoly(5,points1);
- delay(2000);
- cleardevice();
- double xc=0, yc=0;
- double hc=0,jc=0;
- for(int i=0;i<N;i++){
- xc += points1[2*i];
- yc += points1[2*i+1];
- }
- xc/=N;yc/=N;
- double cosa = cos(PI/4), sina = sin(PI/4);
- for(int i=0;i<N+1;i++){
- double xi,yi;
- xi = points1[2*i];
- yi = points1[2*i+1];
- points1[2*i] = xc + (xi-xc)*cosa - (yi-yc)*sina;
- points1[2*i+1] = yc + (xi-xc)*sina + (yi-yc)*cosa;
- }
- for(int i=0;i<2*N+2;i++) poligon[i]=(int)points1[i];
- setcolor(YELLOW);
- drawpoly(N+1,poligon);
- delay(3000);
- float Sx=1.2, Sy=1.2;
- float scal = 0.2;
- for(int i=0;i<N;i++){
- hc += points[2*i];
- jc += points[2*i+1];
- }
- hc/=N;jc/=N;
- while(1)
- {
- // scalare Sx,Sy
- for(int i=0;i<N;i++){
- points[2*i] = hc + (int)((points[2*i] - hc)*Sx);
- points[2*i+1]= jc + (int)((points[2*i+1]- jc)*Sy);
- }
- setcolor(GREEN);
- drawpoly(N,points);
- char c=getch();
- setcolor(BLACK);
- drawpoly(N,points);
- switch(c){
- case 27 : return 0;
- case '+': Sx=Sx+1;Sy=Sy+1;break;
- case '-': Sx=Sx-1;Sy=Sy-1;break;
- case ' ': Sx=Sx+scal;Sy=Sy+scal;
- default: break;
- }
- if( (Sx<0.4) || (Sy>4))scal = -scal;
- }
- closegraph;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement