Outils pour utilisateurs

Outils du site


fractale_de_lyapunov

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
fractale_de_lyapunov [2019/11/16 09:10] Mushussufractale_de_lyapunov [2020/04/07 16:53] (Version actuelle) Mushussu
Ligne 3: Ligne 3:
 ===== C++ ===== ===== C++ =====
 <code c++> <code c++>
 +// Compilation : g++ Lyapunov.cpp -o Lyapunov
 +// Execution   : ./Lyapunov "AB" 1.8 2.2 3.6 4.0 200 200 2000 -1
  
 #include <fstream> #include <fstream>
Ligne 13: Ligne 15:
 using namespace std; using namespace std;
  
-const int largeur = 200, hauteur = 200+int largeur, hauteur; 
-const int iteration = 10000+int iteration; 
-const string sequence = "AAAABBBBBBBBBBBBBBBB";+string sequence
 +float bornes[4]; 
 +float limite;
  
 float proportion(float valeur, float valeurMin, float valeurMax, float valeurOutMin, float valeurOutMax) { float proportion(float valeur, float valeurMin, float valeurMax, float valeurOutMin, float valeurOutMax) {
Ligne 23: Ligne 27:
 } }
  
-int main() {+int main(int argc, char *argv[]) { 
 +    if (argc != 10) { 
 +        cout << "Format : ./Lyapunov \"AB\" 1.8 2.2 3.6 4.0 200 200 2000 -1" << endl; 
 +        return 0; 
 +    } 
 +    // Initialisation des constantes 
 +    sequence = argv[1]; 
 +    for (int i = 0; i < 4; i++) { 
 +        bornes[i] = stof(argv[i + 2]); 
 +    } 
 +    largeur = stoi(argv[6]); 
 +    hauteur = stoi(argv[7]); 
 +    iteration = stoi(argv[8]); 
 +    limite = stof(argv[9]); 
     time_t debut, fin;     time_t debut, fin;
     time(&debut);     time(&debut);
 +
     float  tableau[iteration];     float  tableau[iteration];
     tableau[0]= 0.5;     tableau[0]= 0.5;
Ligne 36: Ligne 55:
     float bValeur[hauteur];     float bValeur[hauteur];
     for (int i = 0; i < largeur; i++) {     for (int i = 0; i < largeur; i++) {
-        aValeur[i] = proportion(i, 0, largeur, 1.82.2);+        aValeur[i] = proportion(i, 0, largeur, bornes[0]bornes[1]);
     }     }
     for (int i = 0; i < hauteur; i++) {     for (int i = 0; i < hauteur; i++) {
-        bValeur[i] = proportion(i, 0, hauteur, 3.64);+        bValeur[i] = proportion(i, 0, hauteur, bornes[2]bornes[3]);
     }     }
-    ofstream image("Imago.pgm");+ 
 +    // Formation du nom du fichier 
 +    string nom  =  "Lyapunov_" + sequence; 
 +    for (int i = 0; i < 4; i++) { 
 +        string s = "_" + to_string(bornes[i]); 
 +        int position = s.find('.'); 
 +        if (position != -1) { 
 +            s[position] = ','; 
 +        } 
 +        nom +=  s; 
 +    } 
 +    nom += ".pgm"
 + 
 +    // Création de l'image 
 +    ofstream image(nom);
     image << "P2" << endl;     image << "P2" << endl;
     image << largeur << " " << hauteur << endl;     image << largeur << " " << hauteur << endl;
Ligne 59: Ligne 92:
  
             int c;             int c;
-            if ((exposant > 0) || (exposant < -1)) {+            if ((exposant > 0) || (exposant < limite)) {
               c = 0;               c = 0;
             } else {             } else {
-              c = floor(proportion(exposant, 0, -1, 255, 0));+              c = floor(proportion(exposant, 0, limite, 255, 0));
             }             }
             image << c << endl;;             image << c << endl;;
         }         }
     }     }
 +
 +
     time(&fin);     time(&fin);
     cout << "Durée = " << difftime(fin, debut) << endl;     cout << "Durée = " << difftime(fin, debut) << endl;
-     +    const string fonction = "open " + nom; 
-    system("open Imago.pgm");+    system(fonction.c_str());
     return 0;     return 0;
 +}
 +</code>
 +
 +====== Processing =====
 +<code java>
 +
 +int iteration = 20000;
 +int valMin = 0;
 +
 +void setup() {
 +size(200, 200);
 +}
 +
 +void draw() {
 +println(hour() + ":" + minute() + ":" + second());
 +loadPixels();
 +for (int i = 0; i < width; i++) {
 + for (int j = 0; j < height; j++) {
 +   float a = map(i, 0, width, 1.8, 2.2);
 +   float b = map(j, 0, height, 3.6,4);
 +   float seq[] = {a, a, a, a, b, b, b, b, b,b ,b , b,b , b, b, b, b, b, b, b}; // AAABBBBBAB
 +   float[]  A = new float[iteration];
 +   A[0]= 0.5;
 +   for (int k = 1; k < iteration; k++) {
 +     A[k] = seq[k % seq.length] * A[k - 1] * (1 - A[k - 1]);
 +   }
 +   float exposant = 0;
 +   for (int k = 1; k < iteration; k++) {
 +     exposant += log(abs(seq[k % seq.length] * (1 - 2 * A[k])));
 +   }
 +   exposant = exposant / iteration;
 +
 +   int c;
 +   if ((exposant > 0) || (exposant < -1)) {
 +     c = 0;
 +   } else {
 +     c = floor(map(exposant, 0, -1, 255, 0));
 +   }
 +   pixels[i + j * width] = color(c);
 + }
 +}
 +updatePixels();
 +saveFrame("Lyapunov" + "-" + year() + "-" + month() + "-" + day() + "-" + hour() + "-" + minute() + "-" + second() + ".png");
 +println(hour() + ":" + minute() + ":" + second());
 +exit(); 
 } }
 </code> </code>
 ===== Liens ===== ===== Liens =====
-https://solarianprogrammer.com/2018/11/19/cpp-reading-writing-bmp-images/+[[https://solarianprogrammer.com/2018/11/19/cpp-reading-writing-bmp-images|C++ lire et écrire des images BMP]]
  
-https://danielbeard.wordpress.com/2011/06/06/image-saving-code-c/+[[https://danielbeard.wordpress.com/2011/06/06/image-saving-code-c|C++ Ecrire une image TGA]]
  
  
 === PPM === === PPM ===
-https://www.youtube.com/watch?v=fbH005SzEMc+[[https://www.youtube.com/watch?v=fbH005SzEMc|C++ Tuto vidéo écrire une image PPM]]
  
-https://www.scratchapixel.com/lessons/digital-imaging/simple-image-manipulations+[[https://www.scratchapixel.com/lessons/digital-imaging/simple-image-manipulations|Manipulation d'images simples]] 
 +{{tag>c++ Processing sylvain}}
fractale_de_lyapunov.1573895434.txt.gz · Dernière modification : 2019/11/16 09:10 de Mushussu