(
Latest Revision:
Oct 13 23:34 PDT 2013
)
edit instructions
Edit Instructions
Here are instructions on how to transform the ascii figure of the bat into
C++ code for drawing the bat on the screen.
Make a copy of the MakeOneBat() function shell in a separate
file
Start up a jove session to edit that file.
Paste a copy of the bat into the function body so it looks like this:
void MakeOneBat()
{
/* code for function MakeOneBat goes in here,
between the braces. */
=, (\_/) ,=
/`-'--(")--'-'\
jgs / (___) \
/.-.-./ | | \.-.-.\
" "
}
Move the cursor to where it is positioned above the bat figure.
Do the following jove command
esc r
(That means tap the escape key and then tap the r-key. You will see this
prompt at the bottom of the terminal window:
: replace-string
Type this: \\
(This tells jove that you want to replace each backslash with something. You
have to type two backslashes above because the backslash is the escape
character for jove)
Then press the enter or return key. Now you will see this at the bottom of
the screen:
: replace-string \\ with
Type this: \\\\
(This means you want to replace each backslash with two backslashes. Since
jove uses the backslash as an escape character, you have to type four of them
when you mean two.)
The command line will now look like this:
: replace-string \\ with \\\\
Press enter again. The editor will replace each backslash in the figure with
two backslashes.
Now move the cursor back so it is above the bat again and use the esc r
command a second time to place a backslash character before each double-quote
character.
Your final command line at the bottom of the screen for this esc r command
will look like this:
: replace-string " with \\"
Once you have executed that command, you can finish off the transformation by
putting
cout << "
at the start of each line of the figure, and placing
\n" ;
at the end of each line of the figure. Now it's code that draws the figure!!
You can create a macro in jove to place the
cout << "
at the start of each line, and the
\n" ;
at the end of each line.
You would move the cursor to the beginning of the first line of the ascii
figure sequence (the bat), then type
ctrl-x (
Now you are defining your macro. You then type
cout << "
then you use the ctrl-e command to move to the end of the line, then type
\n" ;
then use ctrl-a followed by ctrl-n to move to the beginning of the next line.
After that, type
ctrl-x )
to stop recording the macro. Now, after making sure that the cursor is at the
beginning of a line of text that you want to change into a cout statement, if
you type
ctrl-x e
then the macro will execute and transform the line. If you want to transform
several lines at a time, you can do a command of the form
esc n ctrl-x e
This will execute the macro n times, and therefore transform n lines. For
example if you type
esc 3 ctrl-x e
that transforms the next 3 lines into cout statements.