Advertisement
nanobruh

si je perd ca je me suicide donc je le poste sur pastebin

May 23rd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.15 KB | None | 0 0
  1. #include <SFML/Audio.hpp>
  2. #include <SFML/Graphics.hpp>
  3. #include <SFML/System.hpp>
  4. #include <SFML/Window.hpp>
  5. #include <iostream>
  6. #include <vector>
  7. #include <string>
  8. #include <cmath>
  9. #include <tuple>
  10.  
  11. using namespace sf;
  12. using namespace std;
  13.  
  14. const double longueur = 1280;
  15. const double hauteur = 720;
  16. const double e = 1601;
  17. const double k = 1;
  18.  
  19.  
  20. RenderWindow window(VideoMode(longueur, hauteur, 32), "chiass");
  21.  
  22. void string_to_char(string s, char* b){
  23.     int size = s.size();
  24.     for (int x = 0; x < size; x++) {
  25.         b[x] = s[x];
  26.     }
  27. }
  28.  
  29.  
  30. class Particule {
  31.  
  32. public:
  33.  
  34.     Particule(double x, double y,  double charge = 0, double mass = 10000, double radius = 20, double vx = 0, double vy = 0, double ax = 0, double ay = 0) :
  35.         q(charge), m(mass), vx(vx), vy(vy), x(x), y(y), ax(ax), ay(ay), radius(radius)
  36.     {
  37.         circle.setRadius(radius);
  38.         circle.setPointCount(500);
  39.         circle.setFillColor(Color(255, 99, 71));
  40.         circle.setOrigin(radius, radius);
  41.         circle.setPosition(x, y);
  42.     }
  43.        
  44.     void PrintInfo() {
  45.         cout << "Mass = " << (*this).m << endl;
  46.         cout << "Charge = " << (*this).q << endl;
  47.         cout << "X position = " << (*this).x << endl;
  48.         cout << "Y position = " << (*this).y << endl;
  49.         cout << "Vx = " << (*this).vx << endl;
  50.         cout << "Vy = " << (*this).vy << endl;
  51.         cout << "Ax = " << (*this).ax << endl;
  52.         cout << "Ay = " << (*this).ay << endl;
  53.     }
  54.  
  55.     void setcolor(int r, int g, int b) {
  56.         circle.setFillColor(Color(r, g, b));
  57.     }
  58.  
  59.     vector<double> infos() {
  60.         vector <double> infos = {x, y, q, m, vx, vy, ax, ay};
  61.         return infos;
  62.     };
  63.  
  64.     template <class T>
  65.     void SetAcceleration(T ax, T ay) {
  66.         (*this).ax = ax;
  67.         (*this).ay = ay;
  68.     }
  69.  
  70.     template <class T>
  71.     void SetVitesse(T vx, T vy) {
  72.         (*this).vx = vx;
  73.         (*this).vy = vy;
  74.     }
  75.  
  76.     void changeV() {
  77.         vx += ax;
  78.         vy += ay;
  79.     }
  80.  
  81.     void changeXY() {
  82.         x += vx;
  83.         y += vy;
  84.  
  85.     }
  86.  
  87.     void update() {
  88.         changeV();
  89.         /*
  90.         if (vx > 1) {
  91.             vx = 1;
  92.         }
  93.         if (vy > 1) {
  94.             vy = 1;
  95.         }*/
  96.  
  97.         changeXY();
  98.        
  99.         if(x - radius<0) {
  100.             x = radius;
  101.             ax *= -1;
  102.             vx *= -1;
  103.         }
  104.         if (x +radius> longueur) {
  105.             x = longueur- radius;
  106.             ax *= -1;
  107.             vx *= -1;
  108.         }
  109.         if (y - radius< 0) {
  110.             y = radius;
  111.             ay *= -1;
  112.             vy *= -1;
  113.         }
  114.         if (y + radius > hauteur) {
  115.             y = hauteur - radius;
  116.             ay *= -1;
  117.             vy *= -1;
  118.         }
  119.  
  120.         circle.setPosition(Vector2f(x, y));
  121.         window.draw(circle);
  122.     }
  123.  
  124.     void text() {
  125.         Font font;
  126.         if (!font.loadFromFile("arial.ttf"))
  127.             cout << "Merde";
  128.         vector<double> faichier = (*this).infos();
  129.  
  130.         int x = faichier[0];
  131.         char xs[12];
  132.         sprintf_s(xs, "%d", x);
  133.         Text X(xs, font, 20);
  134.  
  135.         int y = faichier[1];
  136.         char ys[12];
  137.         sprintf_s(ys, "%d", y);
  138.         Text Y(ys, font, 20);
  139.         Y.setPosition(50, 0);
  140.  
  141.         window.draw(X);
  142.         window.draw(Y);
  143.  
  144.  
  145.        
  146.     }
  147.  
  148.    
  149.     tuple<double, double> GetAcceleration() {
  150.         return make_tuple(ax, ay);
  151.     }
  152.  
  153.     double distance(Particule *other) {
  154.         return sqrt((other->x - (*this).x) * (other->x - (*this).x) + (other->y - (*this).y) * (other->y - (*this).y));
  155.     }
  156.  
  157.     void coulomb(Particule *other) {
  158.  
  159.         double ax1;
  160.         double ay1;
  161.  
  162.         ax1 = -fabs(other->x - x)*k/ (this->distance(other) * this->distance(other));
  163.         ay1 = -fabs(other->y - y)*k/ (this->distance(other) * this->distance(other));
  164.  
  165.         this->SetAcceleration(ax1,ay1);
  166.         other->SetAcceleration(-ax1,-ay1);
  167.  
  168.     }
  169.  
  170. private:
  171.     double q;
  172.     double m;
  173.     double vx;
  174.     double vy;
  175.     double x;
  176.     double y;
  177.     double ax;
  178.     double ay;
  179.     CircleShape circle;
  180.     int radius;
  181. };
  182.  
  183.  
  184. int main()
  185. {
  186.     Particule electron1(0, 0, -e, 9109);
  187.     Particule electron2(longueur, hauteur, -e, 9109);
  188.  
  189.     ContextSettings settings;
  190.     settings.antialiasingLevel = 32;
  191.     electron1.SetVitesse(1.5, 1.5);
  192.     electron2.SetVitesse(1.5, 1.5);
  193.     electron1.setcolor(255, 255, 255);
  194.     Font font;
  195.     if (!font.loadFromFile("arial.ttf"))
  196.         return EXIT_FAILURE;
  197.    
  198.     while (window.isOpen())
  199.     {      
  200.         Event event;
  201.         Clock clock;
  202.         Text infos;
  203.         while (window.pollEvent(event))
  204.         {
  205.             if (event.type == Event::Closed)
  206.                 window.close();
  207.         }
  208.         window.clear(Color(40, 40, 40));
  209.         electron1.coulomb(&electron2);
  210.         electron1.update();
  211.         electron2.update();
  212.         electron1.text();
  213.         window.display();
  214.     }
  215.     return EXIT_SUCCESS;
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement