On 5/1/2017 10:27 PM, Chris M. Thomasson wrote:
> This compiler just helped me find a bug that compiled right along wrt
> GCC 5.1.0 on windows even using: -Wall -pedantic -Wextra -Wall
[...]
Fwiw, here is my first step at the following code comprised of a single
file Plain PPM generating fractal renderer. Can anybody find any crap in
here, fwiw compiles clean on both lcc-win and my gcc:
** Be warned **, the code creates an output file called
ct_ffe_cipher.ppm. Can you run and open the file in a graphics editor?
It works for me with the Gimp. This non-sense with the hardcoded file
name will change to gain data in the arguments from the command line in
my next iteration of the code. Sorry about the crude state. ;^o
Anyway, the image is rendered with so-called "pretty" colors, the cipher
version, not shown here, makes garbage static. That version will be
completed fairly soon. Anyway, here is the naive first try c99 code, try
to open the resulting file: ct_ffe_cipher.ppm it creates, assuming that
somebody besides me can compile and run it:
_______________________
/* Chris M. Thomasson FFE Cipher Renderer ver:0.0.0.0 (pre-alpha)
5/2/2017 - Raw Experimental
_________________________________________________*/
#include <stdio.h>
#include <assert.h>
#include <complex.h>
#include <tgmath.h>
void
ct_iterate_pixel(
FILE* fout,
double complex z,
double complex c,
unsigned int imax
){
//printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
double o = 999999999999.0;
for (unsigned int i = 0; i < imax; ++i)
{
z = z * z + c;
double dis = cabs(z);
o = (o < dis) ? o : dis;
if (cabs(z) > 256.0)
{
double sum = (i + 1) * (i + .01) * 123U;
unsigned int red = sum;
fprintf(fout, "%u %u %u ", red % 256U, 0, 0);
return;
}
}
//double sum = fabs(creal(z)) + fabs(cimag(z) + o) * 1223456U;
double sum = (o + .01) * 256;
unsigned int red = ((unsigned int)sum) % 256U;
fprintf(fout, "%u %u %u ", 0, red % 256U, 0);
return;
}
void
ct_iterate_plane(
FILE* fout,
unsigned int width,
unsigned int height,
unsigned int imax
){
assert(width > 1 && height > 1);
char const ppm_head[] =
"P3\n"
"# Chris M. Thomasson FFE Cipher Renderer ver:0.0.0.0 (pre-alpha)";
printf("fout:%p\n", (void*)fout);
fprintf(fout, "%s\n%u %u\n%u\n", ppm_head, width, height, 255);
double xstep = 4.0 / (width - 1.0);
double ystep = 4.0 / (height - 1.0);
for (unsigned int y = 0; y < height; ++y)
{
for (unsigned int x = 0; x < width; ++x)
{
double complex z = (-2.0 + x * xstep) + I * (2.0 - y * ystep);
//printf("(%u, %u):z = %.1f%+.1fi\n", x, y, creal(z),
cimag(z));
ct_iterate_pixel(fout, z, z, imax);
}
printf("processing y:%u of %u\r", y + 1, height);
}
printf("\nrender complete!\n");
}
int main(void)
{
FILE* fout = fopen("ct_ffe_cipher.ppm", "w");
assert(fout != NULL);
ct_iterate_plane(fout, 1024, 1024, 128);
fclose(fout);
fflush(stdout);
printf("\n\nFin, hit <ENTER> to exit...\n");
getchar();
return 0;
}
_______________________
Does this work for anybody else at all?