
#include <fstream>
#include <cmath>

int main()
{
  std::ofstream spherefile("sphere256.raw");

  unsigned int nx = 256;
  unsigned int ny = 256;
  unsigned int nz = 256;
  unsigned char insideValue  = 1;
  unsigned char outsideValue = 0;
  const double radius = 125;

  unsigned char value = outsideValue;;

  for(unsigned int x=0; x<nx; x++)
    {
    const double px = static_cast<double>(x) - nx/2;
    for(unsigned int y=0; y<ny; y++)
      {
      const double py = static_cast<double>(y) - ny/2;
      for(unsigned int z=0; z<nz; z++)
        {
        const double pz = static_cast<double>(z) - nz/2;
        const double r  = sqrt( px*px + py*py + pz*pz );
        if( r < radius )
          {
          value = insideValue;
          }
        else 
          {
          value = outsideValue;
          }
        spherefile.put(value);
        }
      }
    }
  spherefile.close();
  return 0;
}



