CS 101 - Intro to Computing, Spring 2010

Lab 4

Running DrJava in the CS Labs

To run DrJava in the CS Labs, you will first need to copy the bookClasses directory and set the classpath. There is a script (i.e. small operating system program) that will do this for you. From a terminal window, enter the following:
     ~i101/setupDrJava
Only enter the above command once.

After the bookClasses directory has been set up, enter the following command to start DrJava:

     ~i101/runDrJava
Once DrJava is up and running, it should work the same as it has on the ACCC's windows machine. Actually is should work better. At least, it will run faster.

Accessing Images with the bookClasses

The book has a number of images that are included on the disk. Those files can be accessed on the LINUX machines using the directory path of:
     ~i101/images
To view a list of the available images, from a terminal window execute the command:
     ls ~i101/images
To copy one of the images to you current director, execute the command:
     cp ~i101/images/XXXXXX.jpg  .
Where XXXXXXis the name of the image you wish to copy.

To have a turtle draw on an image, you must first open the image. The Picture class has a constructor easily do this for you. This constructor takes the filename of the image as its parameter.

The easiest way to get the filename of an image is to use the pickAFile method in the FileChooser class. The pickAFile method will display a dialog box that allow the user to change directories and select an existing file.

The code to prompt the user for a file and then open it is:

     String filename = FileChooser.pickAFile ();
     Picture pict = new Picture (filename);
Once the picture has been opened, that picture can then be used by a turtle for drawing. Check out the code in Lect22a.java for a program that does prompts the user for a file, creates the image and displays the picture.

Lab Assignment

Due: Thursday 2/11/2010 by 11:59 pm

For this lab assignment, complete the following:

  1. Create a "spirograph" style design in a non-blank image.

    The user is to be able to select the non-blank image as shown above in the code Lect22a.java .

    The "spiralgraph style design" will be done by repeatedly drawing shapes and where the orientation of the starting point of the shape is modified between each time the shape is drawn. This simply means that the turtle should be at the some location but facing a different direction. In this manner the shape is to be redrawn enough times to sweep out a complete circle.

    The shape you are to use is a 5 pointed star:

    Note that this shape is not a regular polygon, so you can't just use the methods we used in class. For this shape, instead of just turning once around (360 degrees) as is done with a regular polygon, the figure turns around twice (720 degrees) when being created.

    For this lab, you are to take the star shape and repeat it multiple times, with each star rotated slightly from the previous star. It should look something like:

    The star must be drawn at least 10 times. You can draw it more than 10 times if you wish.

  2. Be sure to include a comment containing the following:

  3. You are also to submit the Java file electronically via the following steps:

    How assignments should be submitted

    1. Go to the blackboard site for the class
    2. Select "Assignments" on the left bar
    3. Locate the correct assignment to submit; click on "View/Complete Assignment" at the bottom of that assignment
    4. Next to "Attach local file", click "Choose file", choose the file you want to submit; please submit only ONE file, properly named.
      For example for lab2, name it Lab2yournetid.java, for example if your Net ID is sfranz3, the filename would be Lab2sfranz3.java
      Please only submit source code file (the .java file, not the .class). Also, if you have any comment about your program, please write it down in the same file; please do NOT write in the "Comments" field on the submission page (this will go into a different file and will be easily missed).
    5. Hit "Submit"
    6. Go back once again to View/Complete assignment and make sure that your file was submitted; also, this page will show your grade and comments (if any) after assignments are graded.

Note that I created the following based on the idea from this lab. I have the size and the color of the star change with respect to the loop counter. Also the shape is drawn in two circles instead of just one.