main.cpp 2.94 KB
Newer Older
plgruener's avatar
plgruener committed
1
#include <vector>
2
#include <random>
plgruener's avatar
plgruener committed
3
#include <cmath>
4
#include <iostream>
plgruener's avatar
plgruener committed
5

6
static const double PI = std::acos(-1);
plgruener's avatar
plgruener committed
7

8
int main(int argc, char* argv[]) {
9

10 11 12 13
  // Default parameters
  int iterations = 100;
  int seedpoints = 10;
  int intervals = 100;
plgruener's avatar
plgruener committed
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  // Get parameters from command line
  if (argc == 1) {
    std::cout << "Warning: Not all parameters were given. Using parameters " 
    << iterations << ", " << seedpoints << ", " << intervals << " .." <<std::endl;
  }
  else if (argc == 2) {
    iterations = atoi(argv[1]);
    std::cout << "Warning: Not all parameters were given. Using parameters " 
    << iterations << ", " << seedpoints << ", " << intervals << " .." <<std::endl;
  }
  else if (argc == 3) {
    iterations = atoi(argv[1]);
    seedpoints = atoi(argv[2]);
    std::cout << "Warning: Not all parameters were given. Using parameters " 
    << iterations << ", " << seedpoints << ", " << intervals << " .." <<std::endl;
  }
  else {
    iterations = atoi(argv[1]);
    seedpoints = atoi(argv[2]);
    intervals = atoi(argv[3]);
  }
36

37 38 39
  double alphabetamax = 1;
  double intervalsize = alphabetamax/intervals;
  std::cout << "intervallsize: " << intervalsize <<std::endl;
plgruener's avatar
plgruener committed
40

41
  // Generate vectors x, y
42
  const int sample_size = seedpoints * intervals * intervals;
43 44 45 46 47
  std::vector<double> x(sample_size);
  std::vector<double> y(sample_size);
  double * x_ = x.data();
  double * y_ = y.data();

48

49
  // Generate seedpoints
50 51
  std::mt19937 gen(std::random_device{}());
  std::uniform_real_distribution<> dis(0, 1);
52
  std::vector<double> randv;
53
  for(int i=0; i < seedpoints; ++i) {
54 55 56 57
    double randn = dis(gen);
    randv.push_back(randn);
  }

58
  // Fill vectors x, y with seedpoints
59 60 61 62 63 64
  int j; 
  for (int i = 0; i < sample_size; ++i) {
    j = i % seedpoints;
    y_[i] = randv[j];
    x_[i] = randv[j];
  }
65

66 67 68 69 70 71
  // Save seedpoints
  std::vector<double> x_start = x;
  std::vector<double> y_start = y;

  // Generate pixel vector
  std::vector<int> pixel(intervals * intervals, 1);
72

73 74
  const double TWO_PI = 2 * PI;
  for (int j = 0; j < iterations; ++j) {
75
    for (int i = 0; i < sample_size; ++i) {
76 77 78
      double beta = ((i / seedpoints) % intervals) * intervalsize;
      double alpha = int((i / seedpoints) / intervals) * intervalsize;
      // std::cout << i << ": beta: " << beta << " -- alpha: " << alpha <<std::endl;
79 80 81
      y_[i] = y_[i] + beta * std::sin(TWO_PI * x_[i]);
      x_[i] = x_[i] + alpha * std::sin(TWO_PI * y_[i]);
    }
82 83
  }

84
  // Map calculated vectors x and y to pixel vector
85
  for (int i = 0; i < sample_size; ++i) {
86 87
    y_start[i] = y_[i] - y_start[i];
    x_start[i] = x_[i] - x_start[i];
88

89 90 91
    if (y_start[i] > 1 || x_start[i] > 1) {
      pixel[int(i / seedpoints)] = 0;
    }
92

93 94
    //std::cout << i << "::: --- y: " << y_start[i] << ", x: " << x_start[i] <<std::endl;
  }
95

96 97
  // Output pixel vector
  for (int i = 0; i < intervals*intervals; ++i){
98 99 100 101
    if ( (i%intervals) == 0) {
      std::cout <<std::endl;
    }
    std::cout << pixel[i];
102
  }
103 104
  std::cout <<std::endl;

plgruener's avatar
plgruener committed
105 106 107

  return 0;
}