// outRaw_patt.cpp - creating a pattern
#include <iostream>
#include <fstream>

int main() {
  using namespace std;
  const int WIDTH = 40;
  const int HEIGHT = 40;
  int numPix = WIDTH*HEIGHT;
  char filename[20];
  unsigned char val = 0; 
  
  cout << "Enter a filename (e.g. pic.raw):";
  cin >> filename;

  ofstream fout(filename);

  for(int i=0;i<numPix;i++) {
    // translating 1d into 2d
    int xval = i%WIDTH;
    int yval = i/WIDTH;

    // creating a gradient between 127-255 spread across the 
    // entire image
    val = char(127+(yval/float(HEIGHT))*128);
    
    // creating a horizontal white line every 8 pixels
    if ((yval)%8 == 0) val = 255; 

    // creating a vertical white line every 4 pixels
    if ((xval)%4 == 0) val = 255; 

    // creating gray dots
    if (xval%4==2 && yval%8==4) val = 127;

    fout << val;
  }
  fout.close();

}
