UNIX Notes
Making Art With Computers – Summer HSSP 2002
Most
operations are performed by typing commands at a “terminal.” To type a command,
enter it with the keyboard and press the “Return” or “Enter” key. We will use a terminal program called
“xterm”. You can start an xterm in one
of two ways:
This
“&” character is important. It
allows us to run the program “xterm” while still entering new commands in the
terminal. If we typed only “xterm”, then we would not be able
to enter new commands at the terminal until we stopped the new xterm program
(by killing the window).
Shortcut! Pressing
the up arrow key will show you the commands you have entered earlier, so you
don’t have to re-type them.
UNIX has a file system that is very similar to that in Windows. This allows us to store “files” in “directories.” The names of files and directories look pretty much the same, but each file or directory is separated by a “/” character. Here are some examples of file and directory names, also called “path names”). (“dir” = “directory” in the lists below.)
/ -
The “root directory”
/tmp -
The directory “tmp” in the root directory
/tmp/art -
The directory “art” in the directory “tmp” in the root dir
Everyone
has a “home directory” which is a special place for files. We give this directory the nickname “~”, but it has a full path
name like any other directory.
~ -
Your “home directory”
~/artwithcomputers -
The directory “artwithcomputers” in your home directory
~/artwithcomputers/axes.pov - The file “axes.pov” in the dir “artwithcomputers” in home dir
Every
terminal has a “working directory” (with the nickname “.”) which gives us an easier
way to access our files. For example, if we want to access the file “/tmp/pictures/axes.pov” and our working
directory is “/tmp/pictures”, then we may access the
file with the name “axes.pov”. This
gives us even more possibilities for path names.
. -
The “working directory”
.. -
The dir above “.” (if “.” = “/tmp/pictures”, “..” = “/tmp”)
../stuff - The directory “stuff” in the directory above “.”.
(if
“.”
= “/tmp/pictures”, “../stuff” = “/tmp/stuff”)
Here
are some terminal commands that will help you work with directories.
pwd - Shows you the “Path” of
the “Working Directory”
ls - Show a “LiSt” of the
files and directories in the working directory
cd dir - “Change the
working Directory” to the directory “dir”
cp file dir - Make a
“CoPy” of the file “file” and put it in the directory “dir”
mkdir dir - “MaKe a new DIRectory”
called “dir” in the working directory
rm file - “ReMove” (delete) the file “file”
As
an example, here are the commands you should enter to get started in each class
session. (The stuff after the dash (-)
is just a note, not something you should type!)
cd /tmp -
Change the working directory to “/tmp”
mkdir art -
Create the directory “art” in the directory “tmp”
cd art -
Change the working directory to “/tmp/art”
pwd -
Check to see that your working directory is “/tmp/art”
cp ~/artwithcomputers/axes.pov . - Copy “axes.pov” from the class dir into your working dir
ls -
List the working dir to make sure “axes.pov” is there
Shortcut! Pressing
the TAB key while typing a file or directory name will complete the name for
you if there is only one name that matches what you have already typed.
To
generate your own images with POV-Ray, you’ll need to create your own scene
file (files that end in “.pov” are scene files) or edit an existing one. I suggest you get started by editing “axes.pov”.
We will do editing with the “Emacs” editor. To start Emacs, type “emacs &” at the terminal.
Opening Files – To open a file, select “Open File” from the file menu. A line at the bottom of the Emacs window will say “Find file:” and as you type the name of the file it will appear here. Pressing the spacebar will show you a list of existing files. Entering a name that does not exist will create a new file. If you followed the instructions above, then you can edit “axes.pov” by simply typing “axes.pov”.
Saving Files – To save a file, select “Save (current buffer)” from the file menu. You’ll know that the file is saved when you see a message like “Wrote /tmp/art/axes.pov” at the bottom of the Emacs window.
Canceling – The above commands for opening and saving files may take many steps. If you decide that you want to cancel any command while it is in progress, press “ctrl-g” (hold the “Control” key and press the “g” key). This will get things back to normal. If you find that strange things are happening, you may need to do this a few times.
Now
for the main event! POV-Ray will
process your scene files and generate images files (that end in “.png” in UNIX). The command will look like the following for
the scene file “axes.pov”.
povray –Iaxes.pov
After
you enter the above command, POV-Ray will begin processing your file and
printing lots of messages to the screen.
If it gets confused, some of these messages will be error messages. You’ll need to look at these messages to
figure out what went wrong. Usually the
problem is that you typed the incorrect name for the file or that there is
something not right in the scene file.
If you enter the above command and all goes well, you should find the
file “axes.png” in your working directory.
An
easy way to view images is with the “XV” viewer. To view the image we just created with XV, type the following
command in the terminal.
xv axes.png &
You’ve
just gone full circle! You can work
with POV-Ray in class by editing the scene file “axes.pov”, regenerating the image
with “povray –Iaxes.pov”, and viewing the image with “xv
axes.png &”.