关于我正在制作的节目,我有3个问题。首先是我的转换方法正确吗?虽然大规模它似乎很好,但在较小的范围内它似乎漂移 - 暗示某种错误。第二个问题是关于我可能在规范化上的可怜尝试。我理解这个概念,而不是细节。你如何从归一化多项式转向RGB是一个显而易见的问题?最后,您会在我的代码中注意到我在编写ppm标头时进行了测试。似乎遵循标准的第一种方法会创建包含内含物的文件,通常是边缘处的红点,或者在某些情况下会出现某种类似的移位?
/** mandel2.c
**
** to compile: gcc -std=c11 -o mand2 mandel2.c
**
**/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <complex.h>
char *Version = "0.008";
/*
Tour of "Seahorse Valley"
-0.75 0.08 0.16 10000
-0.74548 0.11669 0.01276 15000
-0.745067 0.118346 0.0007
-0.744567 0.121201 0.002 1000
-0.7445366 0.1217208 5e-4 1500
-0.74453892 0.12172418 1e-4 2500
-0.744539761 0.121724001 6.25e-6 10000
-0.7445398671 0.1217237421 3.906e-7 25000
-0.74453985651 0.12172377365 3.072e-8
-0.7445398603558 0.1217237736544 9.6e-10
-0.74453986035590 0.12172377389443 6.0e-11
-0.744539860355905 0.121723773894425 7.5e-12
-0.74453986035590837 0.12172377389442482 8e-14
-0.744539860355908380 0.121723773894424824 6.0e-15
-0.7445398603559083806 0.1217237738944248242 7.5e-16
-0.74453986035590838081 0.12172377389442482421 9.375e-17
-0.74453986035590838012 0.12172377389442482241 1.172e-17
*/
typedef struct {
double centerX;
double centerY;
double magnify;
int maxiter;
int cv;
} Parameters;
Parameters parse_command_line ( int argc, char *argv[] ) {
Parameters p;
if (argc > 5) {
p.cv = atoi( argv[5] );
}
else {
p.cv = 64;
}
if( argc > 4 ) {
p.centerX = atof( argv[1] );
p.centerY = atof( argv[2] );
p.magnify = ( 1 / atof( argv[3] ) );
p.maxiter = atoi( argv[4] );
} else {
if( argc > 3 ) {
p.centerX = atof( argv[1] );
p.centerY = atof( argv[2] );
p.magnify = ( 1 / atof( argv[3] ) );
p.maxiter = 500;
} else {
if( argc > 2 ) {
p.centerX = atof( argv[1] );
p.centerY = atof( argv[2] );
p.magnify = 1.0;
p.maxiter = 500;
} else {
if( argc > 1 ) {
p.centerX = atof( argv[1] );
p.centerY = 5.0;
p.magnify = 5.0;
p.maxiter = 500;
} else {
p.centerX = 0.0;
p.centerY = 0.0;
p.magnify = 1.0;
p.maxiter = 500;
}
}
}
}
return p;
}
int main( int argc, char *argv[] ) {
Parameters P = parse_command_line( argc, argv );
int width = 500;
int height = 500;
double MinRe = ( -2.0 / P.magnify ) + P.centerX;
double MaxRe = ( 1.0 / P.magnify ) + P.centerX;
double MinIm = ( -1.2 / P.magnify ) + P.centerY;
double MaxIm = ( MinIm + ( MaxRe - MinRe ) * height / width );
double Re_factor = ( MaxRe - MinRe ) / ( width - 1 );
double Im_factor = ( MaxIm - MinIm ) / ( height - 1 );
int test = 0;
if (test == 1) {
printf( "P6\n" );
printf( "%d %d 255\n", width, height );
printf( "# mand2.exe vr%s %0f %0f %0f %d\n", Version, P.centerX, P.centerY, P.magnify, P.maxiter );
}
else {
printf( "P6\n# mand2.exe vr%s %0f %0f %0f %d\n", Version, P.centerX, P.centerY, P.magnify, P.maxiter );
printf( "%d %d 255\n", width, height );
}
for( unsigned y = 0; y < height; ++y ) {
double c_im = MaxIm - y * Im_factor;
for( unsigned x = 0; x < width; ++x ) {
double c_re = MinRe + x * Re_factor;
double complex C = c_re + c_im * I;
double complex Z = 0;
unsigned n = 0;
for( ; n < P.maxiter; ++n ) {
Z = Z * Z + C;
if( creal( Z ) + cimag( Z ) > 4 )
break;
}
if( n < P.maxiter ) {
int brightness = 256.0 * log( 1.75 + n - log(
log( cabs( Z ) ) ) ) / log( ( double ) P.maxiter );
fputc( ( unsigned char ) brightness, stdout );
fputc( ( unsigned char ) brightness, stdout );
fputc( ( unsigned char ) P.cv, stdout );
} else {
fputc( 0, stdout );
fputc( 0, stdout );
fputc( 0, stdout );
}
}
}
return 0;
}