CS 111 - Program Design I, Fall 2015

Lab 3

Accessing Pictures with the bookClasses

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; 
     filename = FileChooser.pickAFile ();      
     Picture pict;
     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 Lect0916a.java for a program that does prompts the user for a file, creates the image and displays the picture.

Lab Assignment

Due: Wednesday, 9/23/2015 by 11:59 pm

For this lab assignment, you are to create a "spirograph" style design in a non-blank image. The lab is to contain the following operations:

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

  2. The program is to contain a method that draws a 5 pointed star. This method is to take a turtle as its parameter and will not return anything. Check out the code at Lect0917d.java or Lect0917e.java for an example of such methods used to draw using turtles. The shape your method is to draw is a 5 pointed star:
    Note that this shape is not a regular polygon, so you can't just use the same basic ideas we used in class. Fortunately, it is not all that different. 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. The method used to draw a single star is to use a looping statement to repeatly draw the 5 sides of the star.

  3. The "spiralgraph style design" will be done by repeatedly drawing shapes (i.e. calling the draw star method from main) 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 each time the method is called. In this manner the shape is to be redrawn enough times to sweep out a complete circle.

    For this lab, you are to draw the star shape and repeat it multiple times, with each star rotated slightly from the previous star. The repeated steps are to be done using a looping statement like a while loop. When completed, 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.

  4. Be sure to include a comment containing the following:
    • your name
    • your NET-ID
    • day and time of your CS 111 lab section (i.e. Monday at 1:00)
    • A description of the project.
Submission of the Lab

Use the Lab 3 submission link in the Assignments Page of Blackboard for CS 111. You will only need to submit the java source code file. You are to name your file with both the lab number and your NetID so we can find it easier. For someone with the NetId of tsmith14 the file should be named:


Just for Fun

I created the following picture 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.

-- Main.troy - 2015-09-18

This topic: CS111 > WebHome > CS111Fall2015 > AssignmentsF15 > Lab3f15
Topic revision: r1 - 2015-09-18 - 14:48:23 - Main.troy
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF