From: Markus Koenig Date: 2005-10-28T04:22:06+09:00 Subject: Re: ASCII Isometric Graphics... CBlair1986 wrote: > I've just got a bit of a question, here. I suppose my mind's a bit too > tired to think of a solution at the moment, but it's been on my mind > for a while. What I'd like to do is take an array and turn it into an > isometric view of the data, eg: > > [...] Heh, another Ruby quiz. ;) class Array def isowidth first.first.length end def isodepth first.length end alias isoheight length # returns a isometric representation as a String # give the value representing "true" as a parameter def isometric(truevalue = true) # build the graphic lines ascii_width = isowidth * 6 + isodepth * 2 + 1 ascii_height = isoheight * 3 + isodepth * 2 + 1 ascii = Array.new(ascii_height) { " " * ascii_width } # traverse all bricks 0.upto(isoheight-1) do |y| 0.upto(isodepth-1) do |z| (isowidth-1).downto(0) do |x| # only draw certain bricks next if self[y][z][x] != truevalue # calculate the coordinates xa = x * 6 + z * 2 ya = (isoheight-y-1) * 3 + z * 2 # "draw" the brick ascii[ya][xa, 7] = '+-----+' ascii[ya+1][xa, 8] = '|\\ \\' ascii[ya+2][xa, 9] = '| +-----+' ascii[ya+3][xa, 9] = '+ | |' ascii[ya+4][xa+1, 8] = '\\| |' ascii[ya+5][xa+2, 7] = '+-----+' end end end # join the lines return ascii.join("\n") end end data = [[[1, 1], [1, 1]], [[0, 1], [0, 0]]] puts data.isometric(1) Have fun, Markus