RosettaCodeData/Task/Draw-a-cuboid/Phix/draw-a-cuboid-3.phix
2019-09-12 10:33:56 -07:00

27 lines
1.1 KiB
Text

procedure cuboid(integer x,y,z)
--
-- +-+ -- 1) (with x -)
-- / /| -- 2) (times z)
-- Output an x by y by z cube such as +-+ + -- 3) (with x -)
-- | |/ -- 4) (times y)
-- +-+ -- 5) (with x -)
--
-- Nb: trailing '+' shown on stage 3 can occur higher or lower.
--
integer mn = min(y,z)+1, mx = max(y,z)+1,
stage = 1, -- (1..5 as above)
pre = z+1, pad = -1, last = 1
for l=1 to y+z+3 do
integer c = "+/+|+"[stage] -- (front/top corner/edge)
puts(1,repeat(' ',pre)&c&repeat(iff(c='+'?'-':' '),x)&c&
iff(pad>=0?repeat(' ',pad)&"|+/"[last]:"")&"\n")
pre -= pre>0 -- (shrink the initial lhs space prefix)
pad += (l<=mn)-(l>mx) -- +1 early on, -1 later, or both
stage += (c='+') + (l=z+1 or l=y+z+2) -- (can skip 2&4)
last += (last=2 or l=y+1 or l=y+z+2) -- ('|'->'+'->'/')
end for
end procedure
cuboid(0, 0, 0)
cuboid(1, 1, 1)
cuboid(2, 1, 2)
cuboid(3, 2, 1)