aboutsummaryrefslogtreecommitdiff
path: root/mandelbrot.java
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-07-20 18:07:48 -0500
committerCody <cody@codyq.dev>2023-07-20 18:07:48 -0500
commit7c53e65cad365ec112d2ec1bd9c3091dbed05720 (patch)
treedbcac7754608949e6f454726d56b9cea427468d8 /mandelbrot.java
parentee2133a13d61b3b3fb8fcf88f9c9781debd77d9e (diff)
downloadsloth-7c53e65cad365ec112d2ec1bd9c3091dbed05720.tar.gz
Changes
Diffstat (limited to 'mandelbrot.java')
-rw-r--r--mandelbrot.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/mandelbrot.java b/mandelbrot.java
new file mode 100644
index 0000000..1409ce6
--- /dev/null
+++ b/mandelbrot.java
@@ -0,0 +1,40 @@
+public class mandelbrot {
+ public static void main(String[] args) {
+ // char escCode = 0x1B;
+ // System.out.printf("%c[%d;%dH", escCode, 20, 10);
+ // System.out.print("█");
+ // System.out.printf("%c[%d;%dH", escCode, 20, 20);
+ // System.out.print("█");
+ // System.out.printf("%c[%d;%dH", escCode, 30, 10);
+ // System.out.print("█");
+
+ double size = 800;
+ double maxVal = 4;
+ double maxIter = 50;
+ double plane = 4;
+ int x = 0;
+ while (x < size) {
+ int y = 0;
+ while (y < size) {
+ double cReal = (x * plane / size) - 2.0;
+ double cImg = (y * plane / size) - 2.0;
+ double zReal = 0.0;
+ double zImg = 0.0;
+ double count = 0.0;
+ while ((zReal * zReal + zImg * zImg) <= maxVal && count < maxIter) {
+ var temp = (zReal * zReal) - (zImg * zImg) + cReal;
+ zImg = 2.0 * zReal * zImg + cImg;
+ zReal = temp;
+ count = count + 1.0;
+ if (count == maxIter) {
+ char escCode = 0x1B;
+ System.out.printf("%c[%d;%dH", escCode, x, y);
+ System.out.print("█");
+ }
+ }
+ y = y + 1;
+ }
+ x = x + 1;
+ }
+ }
+}