/* Mandelbrot set in Picat. See * http://en.wikipedia.org/w/index.php?title=Mandelbrot_set * http://rosettacode.org/wiki/Mandelbrot_set This solution was inspired by the Icon/Unicon version: http://rosettacode.org/wiki/Mandelbrot_set#Icon_and_Unicon Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. go => Width = 90, Height = 50, Limit = 50, foreach(Y in 1..Height) P="", foreach (X in 1..Width) Z=complex(0,0), C=complex(2.5*X/Width-2.0,2.0*Y/Height-1.0), J = 0, while (J < Limit, c_abs(Z)<2.0) Z := c_add(c_mul(Z,Z),C), J := J + 1 end, if J == Limit then P := P ++ "#" else P := P ++ "." end end, printf("%s\n", P) end, nl. complex(R,I) = [R,I]. c_add(X,Y) = complex(X[1]+Y[1],X[2]+Y[2]). c_mul(X,Y) = complex(X[1]*Y[1]-X[2]*Y[2],X[1]*Y[2]+X[2]*Y[1]). c_abs(X) = sqrt(X[1]*X[1]+X[2]*X[2]).