39 lines
1.2 KiB
Text
39 lines
1.2 KiB
Text
/* NetRexx */
|
|
options replace format comments java crossref symbols nobinary
|
|
|
|
numeric digits 1000
|
|
runSample(arg)
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method runSample(arg) public static
|
|
BLACK_UPPOINTING_TRIANGLE = '\u25b2'
|
|
parse arg ordr filr .
|
|
if ordr = '' | ordr = '.' then ordr = 4
|
|
if filr = '' | filr = '.' then filler = BLACK_UPPOINTING_TRIANGLE
|
|
else filler = filr
|
|
drawSierpinskiTriangle(ordr, filler)
|
|
return
|
|
|
|
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
method drawSierpinskiTriangle(ordr, filler = Rexx '^') public static
|
|
n = 1 * (2 ** ordr)
|
|
line = ' '.copies(2 * n)
|
|
line = line.overlay(filler, n + 1) -- set the top point of the triangle
|
|
loop row = 1 to n -- NetRexx arrays, lists etc. index from 1
|
|
say line.strip('t')
|
|
u = filler
|
|
loop col = 2 + n - row to n + row
|
|
cl = line.substr(col - 1, 1)
|
|
cr = line.substr(col + 1, 1)
|
|
if cl == cr then t = ' '
|
|
else t = filler
|
|
line = line.overlay(u, col - 1)
|
|
u = t
|
|
end col
|
|
j2 = n + row - 1
|
|
j3 = n + row
|
|
line = line.overlay(t, j2 + 1)
|
|
line = line.overlay(filler, j3 + 1)
|
|
end row
|
|
return
|