CS313 Fall 2004
LAB 4

SECOND VI DAY

This is another easy test to see if you can bet better at vi.

Don't forget:   gets you out of insert mode.  If you are
ever confused, hit  then u (to undo your last bad commands).

To refresh your memory, you want to move around a file using
/, to find a string, fx, to find the x in the line, w to move
around a word, - to move up, and  to move down.

You can do things like cw to change a word, or i to insert, or a
to append.  o to open a new line.  cfn to change until you find an n.

Y to yank a line, p to paste.  P to paste ahead of the cursor.
3Y to yank three lines.  yfn to yank from here to the first n.

j goes down in the same column.  . repeats the last destructive command.

:wq or :q! to write, or to quit without saving changes.

1.  Editing an image

Go to this URL:  

http://gigi.cs.wustl.edu/~loui/images/lewis/p0002518.skin2.pnm

save the file, then open it in vi.

This is an image, and it has a header and a body.  In the body, one has
rgb values for each pixel, red, green, then blue.  I want you to change
many of the red values to 255's.  Just wander around the file, using w or
3w to move, making sure you only change the first of every trio of numbers.
(You can use cw to change a value.) Write this file as "yourname.ppm".

2.  Now let's have a look at it.  You can make a jpeg from it
by saying cjpeg yournam.ppm > yourname.jpg.  Now you can view
the jpg by opening it in an image viewing program using your
workstation, or by moving it to public_html, and using the
browser to look at it.  Do you see a lot of red dots that
you put in it?  You may have to enlarge it to see your changes.

3.  Let's be smarter about changing colors.  We'll start adding
blue 255's.  Go back into your file in vi.  Change all the spaces to
tabs.  Do you remember how to use :g/./ s/ /	/g to do this?
Now it's easier to change the third of each r-g-b trio to 255.
Don't forget to change tabs back to spaces when you are done
making changes.  Write and quit this file (:wq).
View this image and verify that you have some blue dots.

4.  Now let's go back into your image.  Try to draw a 5x5 box
in the upper left hand corner of your image (the pixel map starts in
the upper left corner and moves left to right along the top line).
You will need to be able to move from one line to the next by
understanding the width of the image (how do you know that?) and
moving 3*w values forward to get the pixel on the same column,
one line below you.  Your box can be any color you choose (white 
and green are good colors for boxes).

5.  Good luck doing that!  Prove to the TA that you can draw
such a box.

6.  Now write a program in ANY LANGUAGE to draw an nxn box in the
upper left corner.  Prove to the TA that you can do this.