fractale_de_lyapunov
Ceci est une ancienne révision du document !
Fractale de Lyapunov
C++
#include <fstream> #include <iostream> #include <cstdlib> #include <cmath> #include <ctime> #include <string> using namespace std; int largeur, hauteur; int iteration; string sequence; float bornes[4]; float limite; float proportion(float valeur, float valeurMin, float valeurMax, float valeurOutMin, float valeurOutMax) { float valeurOut = (valeur - valeurMin) / (valeurMax - valeurMin); valeurOut = valeurOutMin + valeurOut * (valeurOutMax - valeurOutMin); return valeurOut; } 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; } 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(&debut); float tableau[iteration]; tableau[0]= 0.5; float a, b; float* sequenceTab[sequence.size()]; for (int i = 0; i < sequence.size(); i++) { sequenceTab[i] = (sequence[i] == 'A') ? &a : &b; } float aValeur[largeur]; float bValeur[hauteur]; for (int i = 0; i < largeur; i++) { aValeur[i] = proportion(i, 0, largeur, bornes[0], bornes[1]); } for (int i = 0; i < hauteur; i++) { bValeur[i] = proportion(i, 0, hauteur, bornes[2], bornes[3]); } 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"; ofstream image(nom); image << "P2" << endl; image << largeur << " " << hauteur << endl; image << "255" << endl; for (int y = 0; y < hauteur; y++) { b = bValeur[y]; for (int x = 0; x < largeur; x++) { a = aValeur[x]; for (int k = 1; k < iteration; k++) { tableau[k] = *sequenceTab[k % sequence.size()] * tableau[k - 1] * (1 - tableau[k - 1]); } float exposant = 0; for (int k = 1; k < iteration; k++) { exposant += log(abs(*sequenceTab[k % sequence.size()] * (1 - 2 * tableau[k]))); } exposant = exposant / iteration; int c; if ((exposant > 0) || (exposant < limite)) { c = 0; } else { c = floor(proportion(exposant, 0, limite, 255, 0)); } image << c << endl;; } } time(&fin); cout << "Durée = " << difftime(fin, debut) << endl; const string fonction = "open " + nom; system(fonction.c_str()); return 0; }
Liens
https://solarianprogrammer.com/2018/11/19/cpp-reading-writing-bmp-images/
https://danielbeard.wordpress.com/2011/06/06/image-saving-code-c/
PPM
fractale_de_lyapunov.1573967106.txt.gz · Dernière modification : 2019/11/17 05:05 de Mushussu