Julia集c++;颜色 我目前在做一个作业,我必须在C++中用顺序、并行和OpenCL来生成朱丽亚集。我已经成功地制作了一个图像,但是我使用颜色的方式非常无效。现在有什么想法可以改进代码的颜色部分吗?下面是我代码的顺序部分。如果能帮助我改进颜色设置,我将不胜感激 void sequentialJulia(const complex<float> C, const UINT size = 1000, const UINT MAX_ITERATIONS = 100, const float limit = 1.7f) { int start_s = clock();// starts the timer // Setup output image fipImage outputImage; outputImage = fipImage(FIT_BITMAP, size, size, 24); UINT bytesPerElement = 3; BYTE* outputBuffer = outputImage.accessPixels(); vector<int> colors{ 100, 140, 180, 220, 225 };// this sets the intsity of the image, if i was to remove 225 the image would be darker //vector<int> colors{9, 19, 29, 39, 49 }; //THIS DOESNT WORK DO NOT UNCOMMENT //RGBQUAD color; complex<float> Z; std::cout << "Processing...\n"; for (UINT y = 0; y < size; y++) { //tracking progress; cout << y * 100 / size << "%\r"; cout.flush(); for (UINT x = 0; x < size; x++) { Z = complex<float>(-limit + 2.0f * limit / size * x, -limit + 2.0f * limit / size * y); UINT i; for (i = 0; i < MAX_ITERATIONS; i++) { Z = Z * Z + C; if (abs(Z) > 2.0f) break; } if (i < MAX_ITERATIONS ) { //only changing red byte // bytes per element 9 = blue // bytes per element 2 = red // bytes per element 7 = green outputBuffer[( y * size + x) * bytesPerElement + 9] = colors[i % 5]; } } } cout << "Saving image...\n"; ostringstream name; name << "..\\Images\\" << C << " size=" << size << " mIterations=" << MAX_ITERATIONS << " sequential19.png" ; cout << "saving in: " << name.str().c_str() << "\n"; outputImage.save(name.str().c_str()); cout << "...done\n\n"; int stop_s = clock(); cout << "time: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << endl;// stops the timer once code has executed } void sequentialJulia(常数复数C,常数大小=1000, 常数最大迭代次数=100,常数浮点极限=1.7f){ int start_s=clock();//启动计时器 //设置输出图像 fipImage输出图像; outputImage=fipImage(拟合位图,大小,大小,24); UINT字节数=3; 字节*outputBuffer=outputImage.accessPixels(); 向量颜色{100,140,180,220,225};//这设置了图像的强度,如果我删除225,图像会更暗 //向量颜色{9,19,29,39,49};//这不起作用,不要取消注释 //RGBGUAD颜色; 复Z; std::cout

Julia集c++;颜色 我目前在做一个作业,我必须在C++中用顺序、并行和OpenCL来生成朱丽亚集。我已经成功地制作了一个图像,但是我使用颜色的方式非常无效。现在有什么想法可以改进代码的颜色部分吗?下面是我代码的顺序部分。如果能帮助我改进颜色设置,我将不胜感激 void sequentialJulia(const complex<float> C, const UINT size = 1000, const UINT MAX_ITERATIONS = 100, const float limit = 1.7f) { int start_s = clock();// starts the timer // Setup output image fipImage outputImage; outputImage = fipImage(FIT_BITMAP, size, size, 24); UINT bytesPerElement = 3; BYTE* outputBuffer = outputImage.accessPixels(); vector<int> colors{ 100, 140, 180, 220, 225 };// this sets the intsity of the image, if i was to remove 225 the image would be darker //vector<int> colors{9, 19, 29, 39, 49 }; //THIS DOESNT WORK DO NOT UNCOMMENT //RGBQUAD color; complex<float> Z; std::cout << "Processing...\n"; for (UINT y = 0; y < size; y++) { //tracking progress; cout << y * 100 / size << "%\r"; cout.flush(); for (UINT x = 0; x < size; x++) { Z = complex<float>(-limit + 2.0f * limit / size * x, -limit + 2.0f * limit / size * y); UINT i; for (i = 0; i < MAX_ITERATIONS; i++) { Z = Z * Z + C; if (abs(Z) > 2.0f) break; } if (i < MAX_ITERATIONS ) { //only changing red byte // bytes per element 9 = blue // bytes per element 2 = red // bytes per element 7 = green outputBuffer[( y * size + x) * bytesPerElement + 9] = colors[i % 5]; } } } cout << "Saving image...\n"; ostringstream name; name << "..\\Images\\" << C << " size=" << size << " mIterations=" << MAX_ITERATIONS << " sequential19.png" ; cout << "saving in: " << name.str().c_str() << "\n"; outputImage.save(name.str().c_str()); cout << "...done\n\n"; int stop_s = clock(); cout << "time: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << endl;// stops the timer once code has executed } void sequentialJulia(常数复数C,常数大小=1000, 常数最大迭代次数=100,常数浮点极限=1.7f){ int start_s=clock();//启动计时器 //设置输出图像 fipImage输出图像; outputImage=fipImage(拟合位图,大小,大小,24); UINT字节数=3; 字节*outputBuffer=outputImage.accessPixels(); 向量颜色{100,140,180,220,225};//这设置了图像的强度,如果我删除225,图像会更暗 //向量颜色{9,19,29,39,49};//这不起作用,不要取消注释 //RGBGUAD颜色; 复Z; std::cout,c++,colors,fractals,C++,Colors,Fractals,据我记忆所及,90年代早期的分形生成器(例如:)将迭代紧急援助索引用作256种红-绿-蓝颜色表的索引(这是一个常见的限制,因为当时大多数显示器都限制在这种大小的调色板上) 因此,也许您可以定义一个RGB颜色表,然后查找这些颜色,了解您现在如何执行颜色[i%5];,除非它将输出三种RGB颜色[i%table\u SIZE]。红色,。绿色,。蓝色。我认为最好从单独的文件加载调色板 我一直想知道一个有1000个颜色选项的分形图会是什么样子。我觉得很漂亮 编辑:IIRC Fractint有一个调色板编辑

据我记忆所及,90年代早期的分形生成器(例如:)将迭代紧急援助索引用作256种红-绿-蓝颜色表的索引(这是一个常见的限制,因为当时大多数显示器都限制在这种大小的调色板上)

因此,也许您可以定义一个RGB颜色表,然后查找这些颜色,了解您现在如何执行
颜色[i%5];
,除非它将输出三种RGB颜色[i%table\u SIZE]。红色,
。绿色
。蓝色
。我认为最好从单独的文件加载调色板

我一直想知道一个有1000个颜色选项的分形图会是什么样子。我觉得很漂亮


编辑:IIRC Fractint有一个调色板编辑模式,可以将它们保存到文件中。

除了使用查找表的好主意之外,您还可以在表中的值之间进行插值,而不只是执行模数运算来拾取一个值。因此,您可以拥有一个5色查找表,但可以将其应用于数百或数千次迭代通过在5种颜色之间进行线性插值。例如,如果最大迭代次数为256次,而当前计算需要168次迭代才能转义到无穷大,并且有一个5色查找表,则可以执行此操作以获得颜色:

float lookupVal =  static_cast<float>((colors.size - 1) * i) / MAX_ITERATIONS;
int   lookupIndex  = static_cast<int>(floor(lookupValue));
float fraction  =  lookupVal - floor(lookupVal);
float colorF =  static_cast<float>(colors [ lookupIndex ]) + fraction * static_cast<float>(colors [ lookupIndex + 1 ] - colors [ lookupIndex ]);
uint8_t color = static_cast<uint8_t>(colorF);
float lookupVal=static_cast((colors.size-1)*i)/MAX_迭代次数;
int lookupIndex=static_cast(floor(lookupValue));
浮动分数=lookupVal-地板(lookupVal);
float colorF=static_cast(颜色[lookupIndex])+分数*static_cast(颜色[lookupIndex+1]-颜色[lookupIndex]);
uint8\u t color=静态投影(colorF);

如果查找表具有RGB值而不是灰度值,则需要为每个颜色通道(红色、绿色和蓝色)计算
colorF
color
这个问题需要一些工作。一方面,这不是一个问题。你正在寻找一个代码审查,你也会从中获益。之后,尝试向我们解释我们不熟悉的术语。不是每个C++开发者都知道朱丽亚集是什么,我自己也包括。我不知道我怎么能把它说出来。我已经产生了朱丽亚集的代码。我可以将其更改为红色、绿色或蓝色。但是我希望通过添加更多颜色来改进它,这样做更有意义吗?固定格式不清楚这里发生了什么。据我所知,这里的颜色是24位RGB,但您设置它们的方式完全超出了我的理解。您是否试图直接设置颜色o位图缓冲区,而不是使用适当的API?您现在可以,喜欢。还可以使用系统(如HSV到RGB转换)选择颜色。