Я пытаюсь визуализировать сет Мандельброта с обработкой, и я впервые делаю что-то подобное. Мой подход довольно прост. У меня есть функция Z, которая буквально является основной функцией набора (f(z)=z^2+c
), и я делаю все oop для каждого пикселя экрана, каждый раз, когда я повторяю процесс использования Z () и использования результата в качестве новый параметр z в функции Z () По какой-то причине на экране отображается только диагональная линия, и я понятия не имею, почему это так.
Вот полный код:
void draw() {
int max_iterations = 100, infinity_treshold = 16;
for (int y = 0; y < 360; y++) {
for (int x = 0; x < 480; x++) {
float z = 0; // the result of the function, (y)
float real = map(x,0,480,-2,2); // map "scales" the coordinate as if the pixel 0 was -2 and the pixel 480 was 2
float imaginary = map(y,0,360,-2,2); // same thing with the height
int func_iterations = 0; // how many times the process of the equation has been excecuted
while (func_iterations < max_iterations) {
z = Z(z, real+imaginary);
if (abs(z) > infinity_treshold) break;
func_iterations++;
}
if (func_iterations == max_iterations) rect(x,y,1,1);
}
}
noLoop();
}
private float Z(float z, float c) {
return pow(z,2)+c;
}