The Scroll Art Museum

Scroll art lets beginner programmers turn loops and print() into animated ASCII art.

Connected Pipes

Elongated VIEW FULLSCREEN


Squarish VIEW FULLSCREEN


I wanted to make use of the box-drawing characters to form some sort of random but connected shape, something like the old Pipe Dream game (which apparently was called Pipe Mania when originally released in 1989).

Ensuring that there are no dead ends is a constraint satisfaction problem: I build the pipes one row at a time from left to right. For each space in the row, I consider the adjacent spaces to the left and above. Only the current and previously printed rows need to be kept in memory. The space to the right and below the current space always has both possibilities of connection or no connection. So if there are connections from the left and from above, I know the box-drawing character I choose needs to go to the left and above, but it's random chance as to whether it'll have a connection to the right and below.

There are two forms of this piece, configurable by the VERTICAL_STYLE_FACTOR variable. When set to 1.0, the program never sets the space to have a right-connecting pipe. This should mean that there are only straight vertical lines, because how could there be left-right horizontal connections if there's never a right connection?

I was surprised by this result. But then I realized at the very end, when a space only has only one dead end connection from the left space or the above space, it will randomly include connections down and right. This was a measure I added earlier for more variation, and it was just good fortune it produced the "elongated" vertical effect.

I also feature the squarish form (where VERTICAL_STYLE_FACTOR is set to 0.0) for comparison. You can change this value anywhere within the 0.0 to 1.0 range to set this effect.

Links