TWiki
>
CS111 Web
>
CS111Fall2012
>
AssignmentsF12
>
Lab4f12
(2012-09-20, Main.troy)
(raw view)
E
dit
A
ttach
---++ <a target="_top" href="https://www.cs.uic.edu/bin/view/CS111/">CS 111 - Computer Programming I, Fall 2012</a> ---+++ <a name="Lab_4"></a> Lab 4 ---+++ <a name="Accessing_Images_with_the_bookCl"></a> 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 MAC machines via the *Terminal* application using the directory path of: <pre> ~i101/images </pre> To open the MAC terminal application, click on the MAC Terminal icon: <img alt="" src="http://www.cs.uic.edu/~i101/labs/macterminal.jpg" height="50" /> To view a list of the available images, from a terminal window execute the command: <pre> ls ~i111/images </pre> To copy one of the images to your current director, execute the command: <pre> cp ~i111/images/XXXXXX.jpg . </pre> 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 CS101.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: <pre> String filename; </pre><pre> filename = FileChooser.pickAFile (); </pre><pre> Picture pict;</pre><pre> pict = new Picture (filename); </pre> Once the picture has been opened, that picture can then be used by a turtle for drawing. Check out the code in [[%PUBURL%/CS111/CodeF12/Lect0920c.java][Lect0920c.java]] for a program that does prompts the user for a file, creates the image and displays the picture. ---+++ <a name="Lab_Assignment"></a> Lab Assignment Due: Wednesday 9/26/2012 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 [[%PUBURL%/CS111/CodeF12/Lect0920c.java][Lect0920c.java ]]. <p> </p> 1 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 [[%PUBURL%/CS111/CodeF12/Lect0920d.java][Lect0920d.java]] or [[%PUBURL%/CS111/CodeF12/Lect0920e.java][Lect0920e]].java for an example of such methods used to draw using turtles. The shape your method is to draw is a 5 pointed star: <blockquote> <img alt="" src="http://www.cs.uic.edu/~i101/labs/star5point.jpg" /> </blockquote> Note that this shape is not a regular polygon, so you can't just use the same basic ideas 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. <p> </p> 1 The "spiralgraph style design" will be done by repeatedly drawing shapes (i.e. calling the method) 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. <p> 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: </p><blockquote> <img alt="" src="http://www.cs.uic.edu/~i101/labs/spiralstar2a.jpg" /> </blockquote> The star must be drawn at least 10 times. You can draw it more than 10 times if you wish. <p> </p> 1 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. Friday at 9:00) * A description of the project. *Submission of the Lab* Use the Lab 4 submission link in the Assignments Page of <a target="_top" href="https://blackboard.uic.edu/webapps/login/">Blackboard</a> 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 <a rel="nofollow" href="http://www.cs.uic.edu/bin/edit/CS101/NetID?topicparent=CS101.Lab4s12" title="NetID (this topic does not yet exist; you can create it)">NetID</a> so we can find it easier. For someone with the <a rel="nofollow" href="http://www.cs.uic.edu/bin/edit/CS101/NetId?topicparent=CS101.Lab4s12" title="NetId (this topic does not yet exist; you can create it)">NetId</a> of *tsmith14* the file should be named: <pre> *Lab4tsmith14.java* </pre> *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. <img alt="" src="http://www.cs.uic.edu/~i101/labs/fractal.jpg" /> <a name="topic-actions"></a> <a rel="nofollow" accesskey="e" href="http://www.cs.uic.edu/bin/edit/CS101/Lab4s12?t=1347988981" title="Edit this topic text"> </a> -- Main.troy - 2012-09-20
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2012-09-20 - 17:01:34 - Main.troy
CS111
Web Page Spr 18
Syllabus Spr 18
Lecture Notes Spr 18
Sample Code Spr 18
Assignments Spr 18
[edit this menu
]
Log In
CS 111 Main Page
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
ABOUT US
Our Department
Recent News
Contact Us
ACADEMICS
Prospective Students
Undergraduate
CS Minor
Graduate
Courses
RESEARCH
Overview
By Faculty
Labs
PEOPLE
Faculty
Adjuncts
Staff
Students
Alumni
Copyright 2016 The Board of Trustees
of the University of Illinois.
webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF