Chris_M_Thomasson

Experimental Field Lines

Jul 20th, 2017
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.27 KB | None | 0 0
  1. /* Chris M. Thomasson Field Lines c99
  2. _________________________________________________*/
  3.  
  4. #include <stdio.h>
  5. #include <assert.h>
  6. #include <complex.h>
  7. #include <tgmath.h>
  8.  
  9.  
  10. void
  11. ct_iterate_pixel(
  12.      FILE* fout,
  13.      double complex z,
  14.      double complex c,
  15.      unsigned int imax
  16. ){
  17.      //printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
  18.  
  19.      double o = 999999999999.0;
  20.      double g = 9999999.0;
  21.  
  22.      double complex zp = z;
  23.  
  24.      for (unsigned int i = 0; i < imax; ++i)
  25.      {
  26.          z = z * z + c;
  27.  
  28.          double dis = cabs(z);
  29.  
  30.          o = (o < dis) ? o : dis;
  31.  
  32.          //if (cabs(z) > 256.0)
  33.          if (creal(z) / creal(zp) > g &&
  34.              cimag(z) / cimag(zp) > g)
  35.          {
  36.              double sum = (i + 1) * (i + .01) * 123U;
  37.              unsigned int red = sum;
  38.              fprintf(fout, "%u %u %u  ", red % 256U, 0, 0);
  39.              return;
  40.          }
  41.  
  42.          zp = z;
  43.      }
  44.  
  45.      //double sum = fabs(creal(z)) + fabs(cimag(z) + o) * 1223456U;
  46.      double sum = (o + .01) * 256;
  47.      unsigned int red = ((unsigned int)sum) % 256U;
  48.  
  49.      fprintf(fout, "%u %u %u  ", 0, red % 256U, 0);
  50.  
  51.      return;
  52. }
  53.  
  54.  
  55. void
  56. ct_iterate_plane(
  57.      FILE* fout,
  58.      unsigned int width,
  59.      unsigned int height,
  60.      unsigned int imax
  61. ){
  62.      assert(width > 1 && height > 1);
  63.  
  64.      char const ppm_head[] =
  65.          "P3\n"
  66.          "# Chris M. Thomasson FFE Cipher Renderer ver:0.0.0.0 (pre-alpha)";
  67.  
  68.      printf("fout:%p\n", (void*)fout);
  69.  
  70.      fprintf(fout, "%s\n%u %u\n%u\n", ppm_head, width, height, 255);
  71.  
  72.      double xstep = 4.0 / (width - 1.0);
  73.      double ystep = 4.0 / (height - 1.0);
  74.  
  75.      for (unsigned int y = 0; y < height; ++y)
  76.      {
  77.          for (unsigned int x = 0; x < width; ++x)
  78.          {
  79.              double complex z = (-2.0 + x * xstep) + I * (2.0 - y * ystep);
  80.  
  81.              //printf("(%u, %u):z = %.1f%+.1fi\n", x, y, creal(z), cimag(z));
  82.  
  83.              ct_iterate_pixel(fout, z, z, imax);
  84.          }
  85.  
  86.          printf("processing y:%u of %u\r", y + 1, height);
  87.      }
  88.  
  89.      printf("\nrender complete!\n");
  90. }
  91.  
  92.  
  93. int main(void)
  94. {
  95.      FILE* fout = fopen("ct_ffe_cipher.ppm", "w");
  96.      assert(fout != NULL);
  97.  
  98.      ct_iterate_plane(fout, 1024, 1024, 128);
  99.  
  100.      fclose(fout);
  101.  
  102.      return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment