main.cpp 2.36 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 42
  // Generate pixel vectors
  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 59 60 61 62 63 64
  // Fill pixel vectors with seedpoints
  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
  const double TWO_PI = 2 * PI;
  for (int j = 0; j < iterations; ++j) {
69
    for (int i = 0; i < sample_size; ++i) {
70 71 72
      double beta = ((i / seedpoints) % intervals) * intervalsize;
      double alpha = int((i / seedpoints) / intervals) * intervalsize;
      // std::cout << i << ": beta: " << beta << " -- alpha: " << alpha <<std::endl;
73 74 75
      y_[i] = y_[i] + beta * std::sin(TWO_PI * x_[i]);
      x_[i] = x_[i] + alpha * std::sin(TWO_PI * y_[i]);
    }
76 77 78 79 80 81 82 83
  }

  for (int i = 0; i < sample_size; ++i) {
    std::cout << i << " - y: " << y_[i] << ", x: " << x_[i] <<std::endl;
  }



plgruener's avatar
plgruener committed
84 85 86

  return 0;
}