我正在尝试使用此代码生成圆形图像。
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
double e, f;
double scaler (double a, double b) {
if (a < 256) { e = (-1) * a / 256.0;
if (b < 256) {
f = b / 256.0;
} else {
f = (-1) * (b - 256.0) / 256.0;
}
} else { e = (a - 256.0) / 256.0;
if (b < 256) {
f = b / 256.0;
} else {
f = (-1) * (b - 256.0) / 256.0;
}
}
return e, f;
}
int main () {
int max_color = 255;
int dimention = 512;
ofstream fout;
fout.open("mandeloutput.ppm");
fout << "P3\n" << dimention << " " << dimention << endl << max_color << endl;
for (int i = 0; i < dimention; i++) { f = i;
for (int j = 0; j < dimention; j++) { e = j;
scaler (e, f);
cout << fixed << setprecision(5) << e << " " << f << endl;
if ( e*e + f*f <= 1) {
fout << right << setw(4) << 0 << setw(4) << 0 << setw(4) << 0 << " ";
} else {fout << right << setw(4) << 255 << setw(4) << 255 << setw(4) << 255 << " ";}
}
fout << endl;
}
}
我不明白为什么我的变量e总是 0,为什么我得到标题中描述的关于缩放器内部变量的错误?