分形
分形是永无止境的模式。分形是无限复杂的模式,它们在不同尺度上是自相似的。通过在不断进行的反馈循环中反复重复一个简单的过程来创建它们。数学上的分形可以解释如下。
定义Mandlebrot
Mandelbrot集是函数的复数c的函数从z = 0迭代时不发散,即序列等等,仍然以绝对值为界。简单来说,Mandelbrot集是特定的复数集,在绘制时其分形边界非常复杂。
执行
#include
#include
#include
// Defining the size of the screen.
#define Y 1080
#define X 1920
// Recursive function to provide the iterative every 100th
// f^n (0) for every pixel on the screen.
int Mandle(double _Complex c,
double _Complex t = 0,
int counter = 0)
{
// To eliminate out of bound values.
if (cabs(t) > 4) {
putpixel(creal(c) * Y / 2 + X / 2,
cimag(c) * Y / 2 + Y / 2,
COLOR(128 - 128 * cabs(t) / cabs(c),
128 - 128 * cabs(t) / cabs(c),
128 - 128 * cabs(t) / cabs(c)));
return 0;
}
// To put about the end of the fractal,
// the higher the value of the counter,
// The more accurate the fractal is generated,
// however, higher values cause
// more processing time.
if (counter == 100) {
putpixel(creal((c)) * Y / 2 + X / 2,
cimag((c)) * Y / 2 + Y / 2,
COLOR(255 * (cabs((t * t))
/ cabs((t - c) * c)),
0, 0));
return 0;
}
// recursively calling Mandle with increased counter
// and passing the value of the squares of t into it.
Mandle(c, cpow(t, 2) + c, counter + 1);
return 0;
}
int MandleSet()
{
// Calling Mandle function for every
// point on the screen.
for (double x = -2; x < 2; x += 0.0015) {
for (double y = -1; y < 1; y += 0.0015) {
double _Complex temp = x + y * _Complex_I;
Mandle(temp);
}
}
return 0;
}
int main()
{
initwindow(X, Y);
MandleSet();
getch();
closegraph();
return 0;
}
输出
想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。