CPSC 120 | Principles of Computer Science | Fall 2024 |
Labs are due at the start of lab. It is OK if you show up to lab and copy your files to the handin directory at the very beginning of lab, but this should take at most a couple of minutes and you should not spend the next lab period finishing up the previous week's lab. I will check timestamps, and files handed in more than five minutes after the start of lab will be considered late.
See the policy on late work and extensions.
This lab introduces the systems and software that you'll need to use in this course. Successfully completing this lab means that you are able to:
This handout contains a lot of information. Don't worry about memorizing all of the details the first (or even second or third) time through! Instead, pay attention to understanding the concepts and note what topics there is information about so that you can refer back to the handout for the details when you need them. (Eventually you will need to be able to carry out the tasks without reference to the handout, but it is fine to let that memorization come with use.)
Much of what is in this lab is informational, but there are some things you should actually do:
Actions to take are marked like this, so it is clear when you need to do something.
Some steps might just say "follow along". In that case there isn't anything specific that you need to do, but you should check out what is being talked about in that section e.g. when reading about the Ubuntu desktop, locate the elements mentioned.
This handout is meant to be read in order from beginning to end, so you should do the various tasks in that order. Keep in mind that is a good idea to look through each section or subsection in its entirety before beginning to carry out any actions contained in that section.
Computer science courses at HWS make use of an operating system called Linux. An operating system is the basic software that runs the computer — it controls the hardware of the computer (such as disks and memory) and runs application software (like word processing programs and web browsers). It is the first thing loaded when the computer starts up. You are most likely already familiar with the Microsoft Windows operating system and/or the Macintosh operating system. Linux is a version of Unix, an operating system often used for servers and in academic environments. One reason for Linux's popularity is that it is free and open source, meaning that not only can you download and run it for free, the underlying code is available to anyone to add to and modify.
There are actually many different versions of Linux, known as distributions. HWS uses a version called Ubuntu. Different distributions of Linux all work the same way underneath, but they may look different or be configured differently.
Linux computers are available in Rosenberg 009 and in the Math/CS department lab in Lansing 310.
The Rosenberg 009 computers are dual-boot, meaning that they are configured to run two different operating systems (in this case, Windows and Linux). If the computer is off or running Windows when you sit down at it, you will need to reboot it to switch to Linux. See Operating the Rosenberg 009 Dual Boot Lab Computers for how to do this.
The Lansing 310 computers run only Linux so you should not need to reboot them. If the computer is off, turn it on and wait until the Linux login screen appears.
You can also access a Linux virtual desktop remotely from your own computer. There are two options:
using a web browser (no software installation required) — see Accessing a Virtual Linux Desktop
(recommended) using the desktop client — see Installing the VMware Horizon Virtual Desktop Client
Once you get to a Linux login screen, whether you are in the lab or using a virtual desktop, enter your HWS username and password to log in.
When you are done working or will be away from the computer for a while, it is important to log out (even on a virtual desktop). One reason is security — if you don't log out, anyone who comes along will have access to your account and all your files. Another important reason is etiquette — neither the number of physical computers in the lab nor the number of virtual desktops are unlimited, so tying up a computer you aren't using may block someone else out entirely.
If you will only be away from the computer for a short time, such as for a quick trip to the bathroom, you can lock the screen instead of logging out, but the same etiquette guidelines apply — a locked screen prevents others from using the computer, and a computer locked for a long period of time may get rebooted which risks you losing work if your files aren't saved.
How to log out or lock the screen is covered in the next section ("Navigating the Desktop").
Unlike Windows and MacOS, where the desktop that you interact with is bundled with the rest of the operating system, the desktop in a Linux system is just another component and you'll likely encounter different-looking desktops if you use different Linux distributions.
Follow along.
For a brief introduction to the Ubuntu desktop, see A Beginner's Guide to Ubuntu Linux.
As with Mac and Windows, files in Linux are organized into a hierarchical collection of directories. ("Directory" is the traditional Linux term while "folder" is more associated with Mac and Windows; there are technical distinctions between the terms but from a user perspective both terms refer to the same concept and can be used interchangeably.) Each directory can contain files and/or subdirectories, which in turn contain files and/or subdirectories, and so forth.
Use the Files application to manage your files and directories — copy, paste, rename, delete, and (for directories) create.
Unlike Windows, Linux is case-sensitive so cs120 and CS120 are two different things. Be careful to name things exactly as directed (including case).
When choosing names for files and directories, stick to alphanumeric characters (letters and numbers) and the symbols - (dash) and _ (underscore). Some other characters, such as spaces, are legal to include but require special handling in some contexts, causing problems when I am printing your programs for grading. Please don't use spaces in file and directory names!
Follow along.
You have a home directory which contains your personal files. (This is similar to "My Documents" in Windows.) To go to your home directory, click the Home shortcut in the Files application.
Another directory is the root directory. This directory is the top of the file system — all other files and folders are contained, either directly or indirectly, within the root directory. In other words, you can start at the root directory and repeatedly open subfolders to reach any other file or folder on the system. To go to the root directory, click on "Other Locations" in the Files application and then click on "Computer" (which should be the first thing under "On This Computer").
Root and home directories are well-known, and you can simply say "the root directory" or "my home directory" and people will know what you are talking about. (There's also the Home shortcut in Files which lets you jump straight to your home directory.)
For files and other directories, however, it is necessary to give a pathname which specifies where the thing is located within the system's directory structure. Pathnames can be absolute, which means that the path starts from the root directory, or relative, which starts from some other directory.
The notation for writing down pathnames differs from one operating to another. In Linux:
The root directory's path is simply / (just a slash).
Absolute paths start with /, denoting the root.
Directory names within a path are separated by / and, for files, the filename is appended at the end.
~ (a tilde) refers to your home directory, and ~username refers to the home directory of user username. For example, ~alice refers to home directory of user alice.
For example, the absolute path /home/alice/work/todo.txt refers to a file todo.txt which can be found by starting at the root (/), opening the subdirectory home, opening the subdirectory alice within home, and opening the subdirectory work within alice.
Your home directory is /home/username, where username is your actual username, not the word "username". (For example, the user alice's home directory is /home/alice.) This is the directory you are taken to when you click on the Home shortcut in the Files application; the pathname tells you that you can also get there by starting at the root directory (/), opening the home subdirectory, and then opening the directory with your username within home.
~ provides a shortcut for referring to home directories. This is convenient because every user has their own home directory. For example, ~/work/todo.txt refers to a file todo.txt which can be found by starting in your home directory and opening the subdirectory work within your home directory. ~alice/work/todo.txt refers to a file todo.txt which can be found by starting the user alice's home directory and opening the subdirectory work within alice's home directory. Careful attention to detail is required here — ~alice refers to alice's home directory (/home/alice) while ~/alice refers to a subdirectory called alice within your home directory (/home/username/alice).
Processing stores your sketches in a directory it calls your sketchbook. To keep things organized, put the sketchbook inside another directory holding all of your files for this course. In particular:
Using the Files application, create directories ~/cs120 (for all of your files for this course) and ~/cs120/sketchbook (for your sketches). Be sure to name them exactly as shown, including using lowercase instead of capitals. )
Work for this course will be handed in electronically — no need to print anything! Handing in consists of copying your files to a special handin directory that has been set up so that I can access your work for grading. Your personal handin directory is /classes/cs120/handin/username where username is replaced by your username. (For example, user alice's handin folder is /classes/cs120/handin/alice.)
Using the Files application, navigate to your handin directory.
Processing programs (or sketches as they are called) are created and run within the Processing development environment.
Follow along.
Start Processing using the Applications menu — look for its blue icon on the second page of the menu, or start to type "processing" in the search box.
The first time you start up Processing, you may get a welcome screen with some tips about getting started. Uncheck the "Show this message on startup" box so that you don't continue to get the screen every time you start Processing, then click "Get Started".
By default, Processing uses a sketchbook directory in your home directory to store your Processing sketches. Changing that setting will make it more convenient to get your sketches saved in the right spot and to access them again later. (This is a one-time configuration — you don't need to do it again unless you want to use a different sketchbook directory or run a different installation of Processing, such as on your own computer.)
With Processing running:
Select File->Preferences...
For "Sketchbook folder:", enter the full path /home/username/cs120/sketchbook (starting with / — don't use the ~ shortcut! — and replacing username with your username) for your ~/cs120/sketchbook folder (or click on the little folder icon to browse to it — be careful to choose the sketchbook folder inside your cs120 folder and not the one that Processing created directly in your home directory).
Click OK.
Using the Files application, delete ~/sketchbook — navigate to your home directory, locate the directory sketchbook contained there (be careful not to mix it up with ~/cs120/sketchbook), and delete it.
Processing opens a new sketch window by default when it starts. To create additional new sketches, open a new editor window with File->New instead of creating a new tab in an existing editor window — multiple tabs are for sketches that consist of multiple files, not for separate sketches.
Type your sketch in the editor window.
Save sketches with File->Save (ctrl-S). Make sure you save your sketch frequently (such as each time you run it) so that you don't lose work if Processing or your computer crashes unexpectedly. The first time you save a new sketch, you will be prompted for a name. Check that the path/folder name near the top of the save dialog shows ~username/cs120/sketchbook (there will be a little house icon next to your username instead of a ~), then enter the name in the box labelled "Name:" at the very top of the save dialog.
Run your sketch by clicking on the Play button or using File->Run.
Try this out:
With Processing running:
Copy-and-paste the following example program from chapter 2 into the empty space in the editor window: (if needed, first open a new editor window with File->New)
size(200,200); background(255); // Set ellipses and rects to CENTER mode ellipseMode(CENTER); rectMode(CENTER); // Draw Zoog's body stroke(0); fill(150); rect(100,100,20,100); // Draw Zoog's head fill(255); ellipse(100,70,60,60); // Draw Zoog's eyes fill(0); ellipse(81,70,16,32); ellipse(119,70,16,32); // Draw Zoog's legs stroke(0); line(90,150,80,160); line(110,150,120,160);
Save your sketch with the name lab1 (all lowercase!). Make sure it goes into your ~/cs120/sketchbook folder!
Run the program. You should see a drawing of Zoog, who will be featured in many examples throughout the text.
Open sketches from within Processing rather than clicking or right-clicking on the file from the Files application.
The File->Sketchbook... menu provides easy access to any sketches saved in the sketchbook folder. (Which should be all of them.) If you need to open a sketch saved somewhere else, you can use File->Open... instead.
Hand in the Zoog sketch — using the Files application, locate the lab1 directory inside your sketchbook directory and copy it to your handin directory. Check that it got handed in correctly — using the Files application, navigate to your handin directory, and verify that there is a directory called lab1 inside your handin directory and a file called lab1.pde inside the lab1 directory.
For each of the following, give an absolute path name (starting with / or ~) for the file or directory mentioned. Email your answers to me (bridgeman@hws.edu), putting your answers directly into the body of the email (don't create a separate file and attach it).
If you haven't completed the introductory survey (on Canvas), please do so ASAP.
(optional) If you have a laptop that you can bring to class and/or a computer that you'd like to be able to use instead of coming to the lab, test that you can connect to the Linux VDI — installing the desktop client is recommended but via a web browser is also an option.
You will not generally be able to finish the lab during the lab period. You can use the computers in Rosenberg 009 (when not in use for a class) and Lansing 310, connect to a Linux virtual desktop remotely, or use your own computer if you have Processing installed (see below).
There's not any graded extra credit for this lab, but if you have additional time:
Explore Linux — you might check out what aspects of the environment you can configure (look for Settings on the Application menu) or what applications are available.
Try out more with Processing — create of scene of your choice, either starting from scratch or adding on to the Zoog sketch. Refer to the handout of drawing commands from Wednesday's class (posted on the schedule page). Save your sketch with the name lab1extra.
Accessing Processing through the Linux VDI (or in the lab) is recommended, but it is also possible to install Processing on your computer for better performance or so you can work without a constantly-active network connection.
You will need to download and install two things — Processing (for writing your programs) and FileZilla (to transfer your files between the Linux filesystem and your own computer):
Download Processing from http://processing.org/download/ — look for version 4.3 (it should be the most prominent option on the page) and choose the appropriate version for your computer. You should be able to double-click on the downloaded file to install it once the download is complete.
Download FileZilla from FileZilla — get the FileZilla client (not the server), choosing the appropriate client version for your computer. Choose the plain "FileZilla" edition to get the free version ("FileZilla with manual" and FileZilla Pro have more features but cost money).
Once you've installed Processing, start it up and configure the sketchbook directory as you did above. You should then be good to go.
You will need FileZilla to copy any files from Linux to your computer and vice versa. Once you start FileZilla, do the following to Math/CS department server:
Click Quickconnect.
Note: you must be on campus and connected to HWS Private (or using wired Ethernet) in order for this to work. If you are off campus, there's an extra step of setting up and running VPN. See Configuring Off-Campus Access to the HWS Network [Windows], Configuring Off-Campus Access to the HWS Network [MacOS], and Connecting to HWS Network from Off-Campus (VPN) for more information.
If the connection is successful, you'll see two directory listings. On the left side, labeled "Local site", you'll see your computer. On the right side, labeled "Remote site", you'll see the Linux filesystem.
To copy files, navigate to what you want to copy on one side and where you want to copy it on the other, then drag the file(s)/directories(s) from one side to the other. For example, to hand in a sketch, navigate to your sketchbook directory on your local computer and to the handin directory on the remote Linux filesystem, then drag the entire directory containing that sketch from the left side to the right side.
You can backup your work too — copy the sketch directories from the sketchbook on your computer to ~/cs120/sketchbook on the Linux system.