Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<graphics.h>
- #include<math.h>
- using namespace std;
- int distance(int x1,int y1,int x2,int y2)
- {
- return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- }
- float angle(int x1 , int y1, int x2 , int y2)
- {
- float ang;
- if(x1-x2==0)
- {
- ang=-1.57;
- }
- else
- {
- ang = atan((float)(y1 - y2) / (x1 - x2));
- }
- if (ang < 0 && y1> y2)
- {
- ang += 3.14;
- //cout<<"C";
- }
- else if (ang > 0 && x1 < x2)
- {
- // cout<<"A";
- ang += 3.14;
- }
- return ang;
- }
- int main()
- {
- float x1=200,y1=200,x2=200,y2=200, s=100;
- float vx2=0,vy2=0;
- //int gd = DETECT, gm;
- //int x = 320, y = 240, radius;
- //cout<<&gd;
- initwindow (550, 400,"Windows BGI",50,50, false,true);
- while(1)
- {
- x1=mousex();
- y1=mousey();
- int d1=distance(x1,y1,x2,y2);
- float ang1=angle(x1,y1,x2,y2);
- if(d1-s>0)
- {
- vy2+=(d1-s)*sin(ang1)*.007;
- vx2+=(d1-s)*cos(ang1)*.007;
- }
- // cout<<ang1*180/3.14<<endl;
- vy2+=.23;
- y2+=vy2;
- x2+=vx2;
- vy2*=.99;
- vx2*=.99;
- circle(x1,y1,25);
- circle(x2,y2,25);
- line (x1,y1,x2,y2);
- delay(40);
- swapbuffers();
- cleardevice();
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement