main.cpp 2.23 KB
Newer Older
plgruener's avatar
plgruener committed
1
#include <vector>
2
#include <algorithm>
3
#include <random>
plgruener's avatar
plgruener committed
4
#include <cmath>
5
#include <iostream>
6
#include <fstream>
7
#include <cassert>
plgruener's avatar
plgruener committed
8

9
static const double PI = std::acos(-1);
10 11 12 13 14 15 16 17 18
static const double TWO_PI = 2 * PI;

// return gray-value of pixel[alpha,beta], between 0..255
int pixel(double alpha, double beta, std::vector<double> seed_x, std::vector<double> seed_y, int num_iterations) {
  int num_seeds = seed_x.size();
  assert(seed_y.size() == num_seeds);
  
  std::vector<double> x = seed_x;
  std::vector<double> y = seed_y;
19 20
  
  double d = 0.0;
21

22 23
  for (int i=0;i<num_iterations && d<1;i++) {
    for (int s=0;s<num_seeds;s++) {
24
      y[s] = y[s] + beta * std::sin(TWO_PI * x[s]);
25 26
    }
    for (int s=0; s<num_seeds;s++){
27 28 29
      x[s] = x[s] + alpha * std::sin(TWO_PI * y[s]);
    }

30 31 32
    for (int s=0;s<num_seeds;s++) {
      d = std::max(d,std::abs(y[s]));
    }
33 34 35 36 37 38 39 40
  }
  
  if (d>1) { 
    return 255;
  } else {
    return (int) 254*d;
  }
}
plgruener's avatar
plgruener committed
41

42
int main(int argc, char* argv[]) {
43

44
  // Default parameters
45
  int num_iterations = 100;
46
  int num_intervals = 2000;
47
  int num_params = num_intervals + 1;
48

49 50
  double alphabetamin = 0;
  double alphabetamax = 2;
51
  double intervalsize = (alphabetamax-alphabetamin)/(num_intervals);
52
  std::cout << "intervallsize: " << intervalsize <<std::endl;
plgruener's avatar
plgruener committed
53

54 55 56 57
  // fill Parametervectors:
  std::vector<double> params(num_params);
  for (int i=0;i<num_params;i++) {
    params[i] = alphabetamin + i*intervalsize;
58 59
  }

plgruener's avatar
plgruener committed
60
  std::vector<double> x_start = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
61 62
  //std::vector<double> y_start = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9};
  std::vector<double> y_start = {0,0,0,0,0,0,0,0,0};
63

64 65 66 67
  // Output pixel vector into PGM File
  std::string filename = "picture.pgm";
  std::ofstream ostrm(filename);
  ostrm << "P2" << '\n';
68
  ostrm << num_params << ' ' << num_params << '\n';
69
  ostrm << 255 << '\n'; // max. gray value
70 71 72
  std::vector<int> buffer(num_params*num_params);
  
#pragma omp parallel for
73 74
  for (int j=num_params-1;j>=0;j--) {
    for (int i=0;i<num_params;i++) {
Christoph Saffer's avatar
Christoph Saffer committed
75
     buffer[(num_params-j-1)*num_params+i] = pixel( params[i],params[j], x_start, y_start, num_iterations); 
76
    }
77
  }
plgruener's avatar
plgruener committed
78

79 80 81 82 83 84
  for(int i=0;i<buffer.size();++i) {
    ostrm << buffer[i] << ' ';
    if(i%num_params==0) {
      ostrm << '\n';
    }
  }
plgruener's avatar
plgruener committed
85 86
  return 0;
}