Homework 2 - ASCII Art

ASCII art is a time-honored tradition of computer programmers around the world. ASCII art grew into prominance during the 70s and 80s when the limitations of computers did not allow for users of bulletin board systems (BBS) to transmit images over the wire. Because of this, people improvised by creating crude images with text instead. The term ASCII refers to the canonical english text encoding scheme of the day and is still used today.

Nowdays, ASCII art has taken a life of it's own. In typical Internet speak, ASCII art is still used in the form of emoticons, some simple and some elaborate like the most recent entry in the lexicon, table-flipping guy.

(╯°□°)╯︵ ┻━┻ (if this doesn't render iour browser, then your unicode support is funky!)

ASCII art appears in other places, such as MUDs and Rougelikes, the most venerable of which is Nethack. Finally, even though images are commonplace on the Internet, ASCII art is still used by many for its unique and retro style. The wikipedia article on ASCII art linked above includes many examples of recent ASCII art.

For our purposes, reproducing simple ASCII art is a great next step on our programming journey because we can capture it's repetitive structure with both static methods and for loops. In this homework you'll produce two Java programs that outputs ASCII art tot he console.

Warm-up: ASCII art-a-thon

First, you'll freestyle a piece of ASCII art on your own. Here are the rules:

Include your program in a class called ASCIIArt in a file called ASCIIArt.java (note the capitalization on "ASCII"). You will receive full points for the warm-up as long as it compiles and runs to completion (i.e., does not go into an infinite loop). We'll feature the coolest drawings on the website, so have fun with it!

A Famous Philadelphia Landmark

Next you will reproduce an ASCII rendering of Philadelphia's most famous landmark: the Rocky steps. (Disclaimer #1: I'm from the west coast, and I'm not a touristy-type person, so this may not actually be Philadelphia's most famous landmark.)

             /\
            //\\
           //\/\\
          //\/\/\\
         //\/\/\/\\
---------| %    % |---------
 o o o o | %    % | o o o o 
---------| %    % |---------
~^~^~^~^~/--------\~^~^~^~^~
^~^~^~^~/----------\~^~^~^~^
        |==========|
~^~^~^~/------------\~^~^~^~
^~^~^~/--------------\~^~^~^
      |==============|
~^~^~/----------------\~^~^~
^~^~/------------------\~^~^
    |==================|
   /                    \
  /  ==================  \
 /  / """""""""""""""" \  \
|  | """""""""""""""""" |  |
 \  \ """""""""""""""" /  /
  \  ==================  /
   \____________________/

(Disclaimer #2: I have a degree in computer science, not fine art.)

Like the first homework:

In addition to reproducing this art, you should also introduce a single class constant that controls the number of levels of steps that your program produces. A level of the steps includes two diagonal pieces and a vertical piece, e.g., this is one level:

 ~^~^~^~/------------\~^~^~^~
 ^~^~^~/--------------\~^~^~^
 _._._.|==============|._._._

Include your program in a class called RockySteps in a file called RockySteps.java.

Design details

As with homework 1, you should use static methods to capture the structure of the problem. In particular, you should have a method to draw each subpiece of the drawing and any auxiliary methods to draw subpieces of those subpieces, and so forth.

In homework 2, you should also use for loops to capture the repetitive structure of each line. For example, patterns such as " o", "~^" and "/\" should all be captured in loops rather than repeated in code.

Class constant

As mentioned above, the class constant you introduce to your program should control the number of levels of steps your program produces. Note that your program will still only produce a single picture per invocation. However, if someone changes the value of your constant, then recompiling and rerunning your program should produce a picture with the appropriate number of stairs.

The number of stairs you draw also influences the overall size of your diagram. The size of the middle of the Philadelphia Museum of Art and the roof remains constant. However, additional stairs that you add increase in size going down and consequently increase the size of the roundabout and also the size of the sides of the stairs and building. This effectively keeps the picture centered irrespective of the number of stairs you throw at it.

When adding a class constant to your program, your task will be figuring out which parts relate to the number of level of stairs specified by your program and how they relate.

For reference here is the output of my solution with my constant set to five.

                 /\
                //\\
               //\/\\
              //\/\/\\
             //\/\/\/\\
-------------| %    % |-------------
 o o o o o o | %    % | o o o o o o 
-------------| %    % |-------------
~^~^~^~^~^~^~/--------\~^~^~^~^~^~^~
^~^~^~^~^~^~/----------\~^~^~^~^~^~^
            |==========|
~^~^~^~^~^~/------------\~^~^~^~^~^~
^~^~^~^~^~/--------------\~^~^~^~^~^
          |==============|
~^~^~^~^~/----------------\~^~^~^~^~
^~^~^~^~/------------------\~^~^~^~^
        |==================|
~^~^~^~/--------------------\~^~^~^~
^~^~^~/----------------------\~^~^~^
      |======================|
~^~^~/------------------------\~^~^~
^~^~/--------------------------\~^~^
    |==========================|
   /                            \
  /  ==========================  \
 /  / """""""""""""""""""""""" \  \
|  | """""""""""""""""""""""""" |  |
 \  \ """""""""""""""""""""""" /  /
  \  ==========================  /
   \____________________________/

You can assume that the constant is a positive integer as negative stairs would be weird. Also, when you turn in your program, your class constant should be set to 3 sets of stairs so that your program produces the original output.

How to get started

Drawing the Rocky Steps may seem like a daunting task at first, but if you exercise your skills of problem decomposition, it'll be much more managable. We encourage you to start not by hammering out code, but instead by working out the patterns and formulae in the picture with tables on a piece of paper. Frequently, this is how a computer program starts: a sketch on good ol' paper versus code.

We also highly recommend that you first try to write the program without the class constant in mind. Once you have successfully reproduced the basic diagram, then you should work out how to integrate your class constant. Again, don't be afraid to go back to paper to look for patterns.

Submission

Please submit your two Java source files, ASCIIArt.java and RockySteps.java, electronically via the course website.