Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <Grapic.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8. using namespace grapic;
  9.  
  10. const int DIMW = 500;
  11. const int NB_INSECTES = 100;
  12.  
  13. struct Complex{
  14.     float x, y;
  15. };
  16.  
  17. struct Point{
  18.     int x, y;
  19. };
  20.  
  21. Point makePoint(int x, int y){
  22.     Point pt;
  23.     pt.x = x;
  24.     pt.y = y;
  25.     return pt;
  26. }
  27.  
  28. struct Color{
  29.     unsigned r, g, b;
  30. };
  31.  
  32. struct Insecte{
  33.     Point position;
  34.     Color couleur;
  35.     int dureeVie;
  36. };
  37.  
  38. struct Population{
  39.     Insecte pop[NB_INSECTES];
  40.     int nbInsectes;
  41.     int nbVivants;
  42.     Image paysage;
  43.     int generation;
  44.     int dateNaissance;
  45. };
  46.  
  47.  
  48. void initInsect(Population &pop, Color good, int range, int nbInsectes){
  49.     pop.nbInsectes = nbInsectes;
  50.     pop.nbVivants = nbInsectes;
  51.     for(int i = 0; i < nbInsectes; i++){
  52.         pop.pop[i].position = makePoint(rand()%DIMW, rand()%DIMW);
  53.         pop.pop[i].couleur.r = good.r -range/2 + rand()%(range + 1);
  54.         pop.pop[i].couleur.g = good.g -range/2 + rand()%(range + 1);
  55.         pop.pop[i].couleur.b = good.b -range/2 + rand()%(range + 1);
  56.         pop.pop[i].dureeVie = -1;
  57.     }
  58. }
  59.  
  60. void Init(Population &pop, int nbInsectes, char nomImage[]){
  61.     Color good = {127, 127, 127};
  62.     initInsect(pop, good, 255, nbInsectes);
  63.     pop.paysage = image(nomImage);
  64.     pop.generation = 0;
  65.     pop.dateNaissance = elapsedTime();
  66. }
  67.  
  68. void drawInsectes(Population &pop){
  69.     image(pop.paysage, 0, 0, DIMW, DIMW);
  70.     Color c;
  71.     for(int i = 0; i < pop.nbInsectes; i++){
  72.         if(pop.pop[i].dureeVie == -1){
  73.             c = pop.pop[i].couleur;
  74.             color(c.r, c.g, c.b);
  75.             circleFill(pop.pop[i].position.x, pop.pop[i].position.y, 10);
  76.             //+ffichage nbvivants +vgeneraion
  77.         }
  78.     }
  79. }
  80.  
  81. void minMaxLifeTime(Population pop, int mini, int maxi){
  82.     mini = maxi = pop.pop[0].dureeVie;
  83.     for(int i = 0; i < pop.nbInsectes; i++){
  84.         if(pop.pop[i].dureeVie < mini){
  85.             mini = pop.pop[i].dureeVie;
  86.         }else if(pop.pop[i].dureeVie > maxi){
  87.             maxi = pop.pop[i].dureeVie;
  88.         }
  89.     }
  90. }
  91.  
  92. Color averageColor(Population pop, int dureeeLimite){
  93.     Color c;
  94.     int r, g, b, nb, i;
  95.     r = g = b = nb = 0;
  96.  
  97.     for(i = 0; i < pop.nbInsectes; i++){
  98.         if(pop.pop[i].dureeVie > dureeeLimite){
  99.             r = r + pop.pop[i].couleur.r;
  100.             g = g + pop.pop[i].couleur.g;
  101.             b = b + pop.pop[i].couleur.b;
  102.             nb++;
  103.         }
  104.     }
  105.     c.r = r/nb;
  106.     c.g = g/nb;
  107.     c.b = b/nb;
  108.     return c;
  109. }
  110.  
  111. void update(){
  112.     /*
  113.     position souris mousePos(x, y)
  114.     pour tous les insectes: teste avec mouse, mise a jour duree de vie et nbvivants
  115.     si nbvivants =  -> min max, moyenne couleur good, init insectes.
  116.     */
  117.  
  118. }
  119.  
  120.  
  121. int main(int , char**)
  122. {
  123.     winInit("TD",DIMW, DIMW) ;
  124.     backgroundColor(100, 100, 100);
  125.     bool stop = false;
  126.  
  127.     while( !stop )
  128.     {
  129.  
  130.         stop = winDisplay();
  131.     }
  132.     winQuit();
  133.     return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement