Task

Draw a Cantor set.



See details at this Wikipedia webpage:   Cantor set

cantor = cluster is make
    rep = null
    ac = array[char]
    aac = array[array[char]]
 
    make = proc (width, height: int, ch: char) returns (string)
        lines: aac := aac$fill_copy(0, height, ac$fill(0, width, ch))
        cantor_step(lines, 0, width, 1)
        s: stream := stream$create_output()
        for line: ac in aac$elements(lines) do
            stream$putl(s, string$ac2s(line))
        end
        return(stream$get_contents(s))
    end make
 
    cantor_step = proc (lines: aac, start, len, index: int)
        seg: int := len / 3
        if seg = 0 then return end
        for i: int in int$from_to(index, aac$high(lines)) do
            for j: int in int$from_to(start+seg, start+seg*2-1) do
                lines[i][j] := ' '
            end
        end
        cantor_step(lines, start, seg, index+1)
        cantor_step(lines, start+seg*2, seg, index+1)
    end cantor_step
end cantor
 
start_up = proc ()
    po: stream := stream$primary_output()
    cs: string := cantor$make(81, 5, '*')
    stream$puts(po, cs)
end start_up