solution/cw5/mand.fun
changeset 894 02ef5c3abc51
parent 893 54a483a33763
child 895 2f5a87ecdc81
equal deleted inserted replaced
893:54a483a33763 894:02ef5c3abc51
     1 // Mandelbrot program (without character constants)
       
     2 
       
     3 val Ymin: Double = -1.3;
       
     4 val Ymax: Double =  1.3;
       
     5 val Ystep: Double = 0.05;  //0.025;
       
     6 
       
     7 val Xmin: Double = -2.1;
       
     8 val Xmax: Double =  1.1;
       
     9 val Xstep: Double = 0.02;  //0.01;
       
    10 
       
    11 val Maxiters: Int = 1000;
       
    12 
       
    13 def m_iter(m: Int, x: Double, y: Double,
       
    14                    zr: Double, zi: Double) : Void = {
       
    15   if Maxiters <= m
       
    16   then print_star() 
       
    17   else {
       
    18     if 4.0 <= zi*zi+zr*zr then print_space() 
       
    19     else m_iter(m + 1, x, y, x+zr*zr-zi*zi, 2.0*zr*zi+y) 
       
    20   }
       
    21 };
       
    22 
       
    23 def x_iter(x: Double, y: Double) : Void = {
       
    24   if x <= Xmax
       
    25   then { m_iter(0, x, y, 0.0, 0.0) ; x_iter(x + Xstep, y) }
       
    26   else skip()
       
    27 };
       
    28 
       
    29 def y_iter(y: Double) : Void = {
       
    30   if y <= Ymax
       
    31   then { x_iter(Xmin, y) ; new_line() ; y_iter(y + Ystep) }
       
    32   else skip() 
       
    33 };    
       
    34 
       
    35 
       
    36 y_iter(Ymin)