progs/fun2/mand.fun
changeset 820 7fd1f611c21d
child 854 ce4a7bab6bd8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/fun2/mand.fun	Sat Dec 19 00:13:58 2020 +0000
@@ -0,0 +1,36 @@
+// Mandelbrot program
+
+val Ymin: Double = -1.3;
+val Ymax: Double =  1.3;
+val Ystep: Double = 0.05;  //0.025;
+
+val Xmin: Double = -2.1;
+val Xmax: Double =  1.1;
+val Xstep: Double = 0.02;  //0.01;
+
+val Maxiters: Int = 1000;
+
+def m_iter(m: Int, x: Double, y: Double,
+                   zr: Double, zi: Double) : Void = {
+  if Maxiters <= m
+  then print_star() 
+  else {
+    if 4.0 <= zi*zi+zr*zr then print_space() 
+    else m_iter(m + 1, x, y, x+zr*zr-zi*zi, 2.0*zr*zi+y) 
+  }
+};
+
+def x_iter(x: Double, y: Double) : Void = {
+  if x <= Xmax
+  then { m_iter(0, x, y, 0.0, 0.0) ; x_iter(x + Xstep, y) }
+  else skip()
+};
+
+def y_iter(y: Double) : Void = {
+  if y <= Ymax
+  then { x_iter(Xmin, y) ; new_line() ; y_iter(y + Ystep) }
+  else skip() 
+};    
+
+
+y_iter(Ymin)
\ No newline at end of file