~i101/imagesTo open the MAC terminal application, click on the MAC Terminal icon:
ls ~i101/imagesTo copy one of the images to your current director, execute the command:
cp ~i101/images/XXXXXX.jpg .Where XXXXXX is 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 Lect00202b.java for a program that does prompts the user for a file, creates the image and displays the picture.
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 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.![]()
*Lab4tsmith14.java*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.
Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu |
WISEST Helping Women Faculty Advance Funded by NSF | ![]() | ![]() |