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:
- Make it original! Don't steal it from the interwebs or anywhere else ASCII
art pervades.
- Obviously, don't draw anything offensive or otherwise inappropriate things.
What would your mother think!?
- Your program for this warm-up should not consistent entirely of the solution
for the main part of the assignment below. It is fine to share some pieces but
there should be some original bits as well!
- Your drawing should take up at least five lines on the console. For
sanity's sake, keep it under 100 lines on the console and make sure no line
spans longer than 200 columns (i.e., 200 spaces and characters per line).
- Your program should contain at least one "load-bearing" for loop or static
method. By "load-bearing", I mean that the for loop or static method should be
doing some meaningful work (i.e., generating a pattern or factoring out some
code). In computer speak, we call chunks of code that do nothing a noop
(short for No operation).
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:
- You should reproduce the output exactly, including identical characters and
spacing.
- Instead of simply having one println per line of the drawing, you should
use static methods to decompose the problem and remove redundancy. Also, the
repetitive patterns you see above should be captured with for loops.
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.