public class EscapeJava { public static void main(String[] args) { for (int i = 0; i < 100; i++) { } var a = calculate(generateGrid(100), 100); System.out.println(a); } public static int escape(double cx, double cy, int maximum, double bounds) { int i = 0; double x = 0; double y = 0; while (Math.sqrt(x * x + y * y) < bounds && i < maximum) { y = 2 * x * y + cy; x = x * x - y * y + cx; i++; } return i; } static class Complex { public double real; public double imag; Complex(double real, double imag) { this.real = real; this.imag = imag; } } public static Complex[][] generateGrid(int n) { Complex[][] grid = new Complex[n][n]; for (int yi = 0; yi < n; yi++) { for (int xi = 0; xi < n; xi++) { double cx = -2.0 + (4.0/n) * xi; double cy = -2.0 + (4.0/n) * yi; grid[yi][xi] = new Complex(cx, cy); } } return grid; } public static int[][] calculate(Complex[][] grid, int n) { int[][] results = new int[n][n]; for (int yi = 0; yi < n; yi++) { for (int xi = 0; xi < n; xi++) { Complex c = grid[yi][xi]; results[yi][xi] = escape(c.real, c.imag, 10, 2); } } return results; } }