V22.0002.002 -- Summer, 2011
Nathan Hull
ASSIGNMENT 6
Due: Monday, August 1st
Write a program that reads in (from a disk file) the width of a character, followed
by a string from INPUT and outputs a series of FOURTEEN-SEGMENT characters using
turtle graphics. (Read about Fourteen-Segment
Display and see an animated display of all the characters.)
Any characters not supported by display should simply
be skipped on output.
Your program should print out the letters horizontally, and go to a new "line"
when you input a space. Thus, each 'word' will be on a different line. Also,
make certain you leave some space between each letter.
Your program should be completely structured and use at least three levels
of functions - as described below.
First, here is an example of the fourteen segments all displayed at once. (Note
that your version does NOT have to have points at the end of the segments:
They can simply be straight lines.)
You should produce functions for each letter, for each number and for the
'space' character. For example, the
function for A would not directly call its seven segments directly, but
would be composed of perhaps four further calls:
def MethodA (width) :
top_stroke(width)
middle_stroke(width)
left_stroke
right_stroke(width)
|
![A](segments/A.gif) |
Note that the *width* of a character needs to be sent to any function which is dependent upon it. If you define the lower-right
corner as the "home position" for the turtle, it does *not* need to know the width of the letter to draw the left_stroke, but
it *does* need to know the width to draw the right_stroke in order to position properly.
The code for right_stroke might look like:
def right_stroke(width):
top_right(width)
bottom_right(width)
|
![A](segments/right.gif) |
Finally, bottom_right would actually call the turtle graphics routines and at long last draw a single line.
def bottom_right(width):
*some turtle graphic
functions*
|
![A](segments/bottom_right.gif) |
On the other hand, the letter "H" would be produced by the following
sequence:
Def MethodH( width) :
right_stroke(width)
left_stroke
middle_stroke (width)
|
![A](segments/H.gif) |
Hint: Always make your turtle go back to the same point (say, the lower right) after drawing each stroke.
That way, the order of the strokes will not matter!
So, if you user types:
108 (the width of the character!)
PYTHON IS FUN
The output should look like:
PART TWO:
-
When you are done and have tested it, post your source file "smith_john_assign6"
to Blackboard.
Notes about your program:
- Make sure your program includes a comment at the beginning of the program,
listing your personal
info along with a brief synopsis of the program's function.
- You should use comments throughout the source code to explain key steps
and calculations.
- Choose intuitive names for variables.