Mandelbrot set

You are encouraged to solve this task according to the task description, using any language you may know.


Task

Generate and draw the Mandelbrot set.



Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .




 
use: cx;
 
define: max 4.0;
define: max-iter 570;
 
let: (max-x max-y) screen-size;
let: max-cx $max-x 2.0 /;
let: max-cy $max-y 2.0 /;
let: rows Stack<Str> new;
let: buf Buf new;
let: zoom 0 ref;
 
func: render()()
  $rows clear
 
  $max-y 2 / {
    let: y;
    $buf 0 seek
 
    $max-x {
      let: x;
      let: (zx zy) 0.0 ref %%;
      let: cx $x $max-cx - $zoom deref /;
      let: cy $y $max-cy - $zoom deref /;
      let: i #max-iter ref;
 
      {
        let: nzx $zx deref ** $zy deref ** - $cx +;
	$zy $zx deref *2 $zy deref * $cy + set
	$zx $nzx set
        $i &-- set-call	
        $nzx ** $zy deref ** + #max < $i deref and
      } while
 
      let: c $i deref % -7 bsh bor 256 mod;
      $c {$x 256 mod $y 256 mod} {0 0} if-else $c new-rgb $buf set-bg
      @@s $buf print
    } for
 
    $rows $buf str push   
  } for
 
  1 1 #out move-to
  $rows {#out print} for
  $rows riter {#out print} for;
 
#out hide-cursor
raw-mode
 
let: poll Poll new;
let: is-done #f ref;
 
$poll #in {
  #in read-char _
  $is-done #t set
} on-read
 
{
  $zoom &++ set-call
  render
  $poll 0 wait _
  $is-done deref !
} while
 
#out reset-style
#out clear-screen
1 1 #out move-to
#out show-cursor
normal-mode
 