Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Grapic.h>
- #include <math.h>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- using namespace grapic;
- const int DIMW = 500;
- const int NB_INSECTES = 100;
- struct Complex{
- float x, y;
- };
- struct Point{
- int x, y;
- };
- Point makePoint(int x, int y){
- Point pt;
- pt.x = x;
- pt.y = y;
- return pt;
- }
- struct Color{
- unsigned r, g, b;
- };
- struct Insecte{
- Point position;
- Color couleur;
- int dureeVie;
- };
- struct Population{
- Insecte pop[NB_INSECTES];
- int nbInsectes;
- int nbVivants;
- Image paysage;
- int generation;
- int dateNaissance;
- };
- void initInsect(Population &pop, Color good, int range, int nbInsectes){
- pop.nbInsectes = nbInsectes;
- pop.nbVivants = nbInsectes;
- for(int i = 0; i < nbInsectes; i++){
- pop.pop[i].position = makePoint(rand()%DIMW, rand()%DIMW);
- pop.pop[i].couleur.r = good.r -range/2 + rand()%(range + 1);
- pop.pop[i].couleur.g = good.g -range/2 + rand()%(range + 1);
- pop.pop[i].couleur.b = good.b -range/2 + rand()%(range + 1);
- pop.pop[i].dureeVie = -1;
- }
- }
- void Init(Population &pop, int nbInsectes, char nomImage[]){
- Color good = {127, 127, 127};
- initInsect(pop, good, 255, nbInsectes);
- pop.paysage = image(nomImage);
- pop.generation = 0;
- pop.dateNaissance = elapsedTime();
- }
- void drawInsectes(Population &pop){
- image(pop.paysage, 0, 0, DIMW, DIMW);
- Color c;
- for(int i = 0; i < pop.nbInsectes; i++){
- if(pop.pop[i].dureeVie == -1){
- c = pop.pop[i].couleur;
- color(c.r, c.g, c.b);
- circleFill(pop.pop[i].position.x, pop.pop[i].position.y, 10);
- //+ffichage nbvivants +vgeneraion
- }
- }
- }
- void minMaxLifeTime(Population pop, int mini, int maxi){
- mini = maxi = pop.pop[0].dureeVie;
- for(int i = 0; i < pop.nbInsectes; i++){
- if(pop.pop[i].dureeVie < mini){
- mini = pop.pop[i].dureeVie;
- }else if(pop.pop[i].dureeVie > maxi){
- maxi = pop.pop[i].dureeVie;
- }
- }
- }
- Color averageColor(Population pop, int dureeeLimite){
- Color c;
- int r, g, b, nb, i;
- r = g = b = nb = 0;
- for(i = 0; i < pop.nbInsectes; i++){
- if(pop.pop[i].dureeVie > dureeeLimite){
- r = r + pop.pop[i].couleur.r;
- g = g + pop.pop[i].couleur.g;
- b = b + pop.pop[i].couleur.b;
- nb++;
- }
- }
- c.r = r/nb;
- c.g = g/nb;
- c.b = b/nb;
- return c;
- }
- void update(){
- /*
- position souris mousePos(x, y)
- pour tous les insectes: teste avec mouse, mise a jour duree de vie et nbvivants
- si nbvivants = -> min max, moyenne couleur good, init insectes.
- */
- }
- int main(int , char**)
- {
- winInit("TD",DIMW, DIMW) ;
- backgroundColor(100, 100, 100);
- bool stop = false;
- while( !stop )
- {
- stop = winDisplay();
- }
- winQuit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement