<?xml version="1.0"?>
<moya xmlns="http://moyaproject.com">
    <macro docname="main">
        <!-- <breakpoint /> -->
        <echo>Generates an ASCII mandelbrot set</echo>
        <echo>Run with "moya run mandel.xml -e mandel"</echo>
    </macro>
    <macro docname="mandel">
        <let xsize="80" ysize="20" max_iteration="50"/>
        <let-str chars=" .,~:;+*%@##"/>
        <let xrange="0...xsize" yrange="0...ysize" />
        <for src="yrange" dst="pixy">
            <let y0="(pixy/ysize) * 2 - 1" row="''" />
            <for src="xrange" dst="pixx">
                <let x0="(pixx/xsize) * 3 - 2"
                     x="0" y="0" dst="0" iteration="0"/>
                <while test="(x*x + y*y) lt 4 and iteration lt max_iteration">
                    <let xtemp="x*x - y*y + x0"
                         y="2*x*y + y0"
                         x="xtemp"
                         iteration="iteration + 1"/>
                </while>
                <let row="row + chars[iteration % 10]" />
            </for>
            <echo>${row}</echo>
        </for>
    </macro>
</moya>
