Files for this lab come from the subdirectory:
~pconrad/public_html/cisc105/04F/labs/lab05
To get started, you should copy all the files from that subdirectory into your own ~/cisc105/lab05 directory.
Note: Previous labs cover the commands for creating
a
new ~/cisc105/lab05
subdirectory and
copying
all
the
files from
my lab05
subdirectory
into your
subdirectory,
so refer to those labs if you are not sure what to do at this step. Next lab
I'll just give you the name of the directory where can find the files and
tell
you to copy them into your own directory.
In this exercise, you will use a program called gnuplot to draw letters of the alphabet. This exercise, together with some future labs, illustrates some of the basic ideas behind how "fonts" work in systems such as Microsoft Windows, Macintosh OS, and the X Windows system used on strauss.
This exercise will begin to teach you what you need to know about gnuplot.
In this exercise, you will first use a text editor (vi or emacs) to create a file that contains points that draw a letter of the alphabet. You will then use gnuplot to plot those points, and store the resulting graphic in an output file. The output file has the extension .png, which stands for "Portable Network Graphics". Files ending in .png are similar to files ending in .gif, .jpg, or .jpeg, except they use a different format for representing the pixels in the image, and for compressing those pixels.
This exercise also assumes you know how to put files on the web under your public_html directory, use the chmod command to make those files readable, and point your web browser at those files.
The link where you must put the files you create with this exercise is:
http://copland.udel.edu/~userid/cisc105/lab05where userid is your strauss userid. Hence, the directory name is:
~/public_html/cisc105/lab05
Gnuplot offers us an easy way to generate graphics from C programs. In future labs, we'll be generating data files using C programs, and then using Gnuplot to visualize that data.
A typical gnuplot data file consists of lines of text, where on each line there are two numbers, representing an (x,y) coordinate. Here is a gnuplot data file called "A.dat", followed by an explanation of its contents:
# A 0 0 2 8 4 0 1 4 3 4 |
set xrange [0:8] set yrange [0:8] set output "A.png" set terminal png large color plot "A.dat" with lines |
Here is an explanation of the
gnuplot commands:
set xrange [0:8] signifies that the x-axis will run from
0 to 8. The set yrange command is similar.
set output "A.png" means that the output graphics will go
to a file called "A.png". You could supply any other file here that you wish,
though it should end with .png if you want it to work properly with your
browser.
set terminal png large color means that we want .png output.
(Note: There are other kinds of output that gnuplot can produce, but we won't
need to know about those for this exercise.)
plot "A.dat" with lines means to get the data points from
the file called "A.dat", and connect the dots with lines. There are other
kinds of plots that gnuplot can do, but we won't need to know about those
in this exercise.
gnuplot A.gnuplot
In the command gnuplot A.gnuplot, the word gnuplot is actually the name of a Unix exectuable program you are running called "gnuplot". The A.gnuplot part signifies the name of the gnuplot command file that you created. That A.gnuplot file refers to two other files: the A.dat file, where the gnuplot program takes the points from, and A.png where gnuplot places the final output as a graphics file. Take a moment to find each of these references in the A.gnuplot file.
Yes, that's a lot of different files and filenames to keep track of. But we beleive in you... you are UD Blue Hens, and you are up to the task!
Now, once you've done the gnuplot A.gnuplot command, to see the file, copy it into a directory on your webpage (i.e. somewhere
under your ~/public_html directory tree) and do the "chmod" command that makes
it readable. You should then be able to point your web browser to the file
and see the output.
Sometimes setting the xrange and yrange commands in the gnuplot file to [-1,8] works better than [0,8]; when you go from -1, the xaxis and yaxis don't cover up part of your letter, and its sometimes easier to see what is going on. Experiment with changing the value from 0 to 1 to see what happens when you repeat the gnuplot command, and copy the resulting .png file to your webpage and refresh.
(Reminder: the required URL for the web page where you should put this .png file was listed earlier in the lab. Be sure you copy the file to the correct place to get full credit!)
You will also see another set of three files. The CIS.dat file and CIS.gnuplot files can be used to produce a CIS.png file. However, note that if you look at the CIS.png file (by pointing a web browser to that file) the S in CIS is incomplete. As an exercise, see if you can modify the points in CIS.dat to make the S complete, and get the correct graphic to come up. That will help check your understanding of how gnuplot works before you go to the next step.
Create a data file called initials.dat that contains the points needed to print your first and last initial. Create each using block capital letters. Put your first initial in a box where the lower left corner is at position 0,0, and the upper right hand corner is at position 4,8. Put your second initial in a box where the lower left hand corner is at position 5,0, and the upper right is at position 9,8. That will leave one "point" of space between the two capital letters.
Also create a initials.gnuplot file that will take the input from initials.dat and produce an output file called initials.png. Adjust the xrange and yrange in your gnuplot file appropriately. (Remember that starting at -1 instead of 0 may help if some parts of your letter coincide with the x or y axis.)
Submission Instructions
cd ~/public_html/cisc105 emacs index.html |
Here is a link to my <a href="./lab05">lab05 files</a>. |
Grading
Writing a .dat file and a .gnuplot file by hand can be tedious. If we are going to plot a large graphic, we might want to write a program to do it instead. In a future lab, we'll do just that.