Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define USE_CONSOLE
- #define _USE_MATH_DEFINES
- #include<iostream>
- #include<cmath>
- #include<allegro.h>
- #define XRES 640
- #define YRES 640
- using namespace std;
- const int k=5000;
- double const G=6.67e-8;
- double const m=10000000000000;
- double const M=10000000000000;
- double const Q=10000000000000;
- double const dt=0.07;
- int konwersjaX(double x, double xmin, double xmax, int W)
- {
- return W*(x-xmin)/(xmax-xmin);
- }
- int konwersjaY(double y, double ymin, double ymax, int H)
- {
- return H-H*(y-ymin)/(ymax-ymin);
- }
- int main()
- {
- double vx, vy, ua, ub, r1, r2, r3, wc, wd;
- double alfa=180, beta=0, gamma=180; //M / m
- double v=10, u=37, w=40;
- allegro_init();
- install_keyboard();
- set_color_depth(desktop_color_depth());
- set_gfx_mode( GFX_AUTODETECT_WINDOWED, XRES, YRES, 0, 0);
- double x=0, y=0, a=0, b=400, c=0, d=-400; // M / m / Q
- alfa=alfa*M_PI/180;
- beta=beta*M_PI/180;
- gamma=gamma*M_PI/180;
- vx=v*cos(alfa);
- vy=v*sin(alfa);
- ua=u*cos(beta);
- ub=u*sin(beta);
- wc=w*cos(gamma);
- wd=w*sin(gamma);
- for(int i=0; i<500000; i++)
- {
- r1=sqrt(pow((x-a), 2)+pow((y-b),2));
- r2=sqrt(pow((x-c), 2)+pow((y-d),2));
- r3=sqrt(pow((c-a), 2)+pow((d-b),2));
- vx=vx+(a-x)*dt*G*m/pow(r1, 3)+(c-x)*dt*G*Q/pow(r2, 3); // ciało o masie M
- vy=vy+(b-y)*dt*G*m/pow(r1, 3)+(d-y)*dt*G*Q/pow(r2, 3);
- ua=ua-(a-x)*dt*G*M/pow(r1, 3)+(c-a)*dt*G*Q/pow(r3, 3); //ciało o masie m
- ub=ub-(b-y)*dt*G*M/pow(r1, 3)+(d-b)*dt*G*Q/pow(r3, 3);
- wc=wc-(c-x)*dt*G*M/pow(r2, 3)-(c-a)*dt*G*m/pow(r3, 3); // ciało o masie Q
- wd=wd-(d-y)*dt*G*M/pow(r2, 3)-(d-b)*dt*G*m/pow(r3, 3);
- x=x+vx*dt;
- y=y+vy*dt;
- a=a+ua*dt;
- b=b+ub*dt;
- c=c+wc*dt;
- d=d+wd*dt;
- putpixel(screen, konwersjaX(x, -k, k, XRES), konwersjaY(y, -k, k, YRES), makecol(250, 0, 0));
- putpixel(screen, konwersjaX(a, -k, k, XRES), konwersjaY(b, -k, k, YRES), makecol(0, 250, 0));
- putpixel(screen, konwersjaX(c, -k, k, XRES), konwersjaY(d, -k, k, YRES), makecol(0, 0, 250));
- }
- acquire_screen();
- release_screen();
- readkey();
- return 0;
- }
- END_OF_MAIN();
Add Comment
Please, Sign In to add comment