Problem Set 0: Turtle Graphics
|Safe from bugs||Easy to understand||Ready for change|
|Correct today and correct in the unknown future.||Communicating clearly with future programmers, including future you.||Designed to accommodate change without rewriting.|
- introduce the tools we will use in 6.031, including Java, Eclipse, JUnit, and Git;
- introduce the process for 6.031 problem sets;
- and practice basic Java and start using tools from the Java standard library.
Read and complete the Getting Started guide. The guide will step through:
Create your remote repository with the starting code for the problem set by visiting didit.csail.mit.edu/6.031/sp19. Go to
psets/ps0and click the button to create your repository. You will only be able to create a repo after the course signup forms are processed and the problem set is announced.
If you can’t create a repo after the announcement, you are not registered for 6.031. Contact the staff (how?) to check your status.
Getting Started step 5 introduces the command line.
Note: Getting Started step 6 has setup you must perform before using Git.
Find your clone URL at the top of your
psets/ps0page on Didit. It will look like this, with your username filled in:
git clone «URL»
git clonesays “does not appear to be a git repository” or “could not read from remote repository”, check your repository URL for typos. Make sure your repository is listed on Didit.
Check that you can authenticate to
github.mit.eduin the last part of Getting Started step 6.
If you are a listener or not taking 6.031 for credit, you can clone problem set repositories using a modified URL: after
ps0, omit the dash-username. You will not be able to push to this repository, it’s a read-only remote.
Note: Getting Started step 4 has setup you must perform before using Eclipse in 6.031.
- In Eclipse, go to File → Import… → General → Existing Projects into Workspace.
- Select the root directory of your clone by clicking “Browse…” and navigating to it.
- Make sure the project is checked, make sure “Copy projects into workspace” is not checked, and click Finish.
I can write my solution while sitting near another person writing theirs.
I can write my solution while sitting near another person writing theirs, reading code aloud to each other to make sure we both got it.
Logo is a programming language created at MIT that originally was used to move a robot around in space. Turtle graphics, added to the Logo language, allows programmers to issue a series of commands to an on-screen “turtle” that moves, drawing a line as it goes. Turtle graphics have also been added to many different programming languages, including Python, where it is part of the standard library.
Moves the turtle in the current direction by units pixels, where units is an integer. Following the original Logo convention, the turtle starts out facing up.
Rotates the turtle by angle degrees to the right (clockwise), where degrees is a double precision floating point number.
Once you’ve implemented the method, run the
TurtleSoup.java. To run
main, right-click on the file
TurtleSoup.javain the Package Explorer on the left side of Eclipse, go to Run As, and select Java Application.
mainmethod creates a new turtle, calls your
drawSquaremethod, and instructs the turtle to draw on screen. A window will pop up, and, once you click the “Run!” button, you should see a square drawn on the canvas.
which shows you files that have been created, deleted, and modified in the project directory. You should see
TurtleSoup.javalisted under “Changes not staged for commit.” This means Git sees the change, but you have not (yet) asked Git to include the change as part of your next commit.
will actually commit the changes locally, after opening your default editor to allow you to write a commit message. Your message should be formatted according to the Git standard: a short summary that fits on one line, followed by a blank line and a longer description if necessary.
If Git warns you about configuring your default identity or you can’t edit your commit message, you did not follow the instructions in the Getting Started guide. Getting Started step 6 has setup you must perform before using Git.
to see the history of commits in your project. Right now, you should see three of them: an initial commit with the starting code, a commit when you created your problem set repo, and the commit you made just now.
Important: only the local history has the new commit at this point; it is not stored in your remote repository. This is one important aspect where Git is different from centralized systems such as Subversion and CVS.
At this point, the remote repository on GitHub.mit now has the same history as your local repository. It is important to remember that we will be grading the history in the repository on GitHub.mit; if you forget to push, we won’t see your commits.
Didit: when you push your commit, the Didit system will run a subset of the autograder on your code. Didit clones its own copy of your code from what you’ve pushed to GitHub.mit, compiles it, and runs some tests.
Visit Didit after you push to see the report. Right now, almost all tests will fail since you’ve only implemented one method. But as the deadline approaches, it is your responsibility to check Didit’s build report and ensure that we can compile and run your code.
GitHub.mit: you can browse the contents of your remote repository by visiting
github.mit.edu/6031-sp19 or following links from Didit to GitHub.mit.
In this problem set, you should only need to edit
You should not change any of the method signatures (what’s a method signature?) in that file, or you risk receiving zero points on the problem set.
Run the public tests that we provided. In 6.031, we use JUnit, a widely-adopted Java testing library. We’ll see more about JUnit, and about testing in general, in an upcoming class. For now, let’s focus on running the provided tests against your implementation. By convention, JUnit tests are in a class whose name ends with
Test, so the public tests for this problem set are in
To run the JUnit tests in
testfolder in the Package Explorer, right-click it, and go to the Run As option. Click on JUnit Test, and you should see the JUnit view appear.
The big red bar indicates that at least one test has failed. That shouldn’t surprise us, since the other tests are exercising methods we haven’t implemented yet. When all the tests pass, the bar will turn green!
testAssertionsEnabledfails, you did not follow the instructions in the Getting Started guide. Getting Started step 4 has setup you must perform before using Eclipse.
You should see a red X or blue X next to
calculateRegularPolygonAngleTestin the JUnit view, and if you click on
calculateRegularPolygonAngleTest, you will see a stack trace in the bottom box, which provides a brief explanation of what went wrong. Double-clicking on a line in the failure stack trace will bring up the code for that frame in the trace. This is most useful for lines that correspond to your code; this stack trace will also contain lines for Java libraries or JUnit itself.
Try double-clicking on the line in the stack trace for
calculateRegularPolygonAngleTest(), and look at the code for the test. On that line, you should see a call to your
calculateRegularPolygonAngleimplementation with particular values for its arguments, within a call to
assertEquals()that checks whether your implementation’s return value was correct. A JUnit test generally has this form: it calls your implementation, then makes one or more assertions about the value that your implementation returned.
Passing the public JUnit tests we provide does not necessarily mean that your code is perfect. You need to review the function specifications carefully. In future problem sets, we’ll also expect you to write your own JUnit tests to verify your code.
Commit to Git. Once you’re happy with your implementations of these functions, commit and push! Committing frequently – whenever you’ve fixed a bug or added a working and tested feature – is a good way to use version control, and will be a good habit to have for your team projects.
This function calculates the parameter to
turnrequired to get from a current point to a target point, with the current direction as an additional parameter. For example, if the turtle is at (0,1) facing 30 degrees, and must get to (0,0), it must turn an additional 150 degrees, so
calculateBearingToPoint(30, 0, 1, 0, 0)would return
Make sure to use your
calculateBearingToPointimplementation here. For information on how to use Java’s
Listinterface and classes implementing it, look up
java.util.Listin the Java library documentation. Note that for a list of n points, you will return n-1 heading adjustments; this list of adjustments could be used to guide the turtle to each point in the list. For example, if the input lists consisted of
yCoords=[1,0,0,1](representing points (0,1), (0,0), (1,0), and (1,1)), the returned list would consist of
[180.0, 270.0, 270.0].
convexHull, which computes the convex hull, the smallest convex set that contains all the points in a set of input points.
The gift-wrapping algorithm is one simple approach to this problem, and there are other algorithms too.
Remember that 6.031 focuses on SFB/ETU/RFC, so your code will not be judged by its performance.
The specification comment above
convexHull requires you to return the “minimal subset of the input points that form the vertices of the perimeter of the convex hull.”
This statement is well-defined on any set of input points.
What should you do for a set of 2 points? 1 point? 0 points?
What should you do for a point that lies on an edge of the convex hull, but is not a vertex of that edge?
For information on how to use Java’s
Set interface and classes implementing it, look up
java.util.Set in the Java library documentation.
In this function, you have the freedom to draw any piece of art you wish. Your work will be judged both on aesthetics and on the code used to draw it. Your art doesn’t need to be complex, but it should be more than a few lines. Use helper methods, loops, etc. rather than simply listing forward and turn commands.
Here are some examples of the kinds of images you can generate procedurally with turtle graphics, though note that many of them use more commands than what we’ve provided here.
main method to see the results of your function.
Make sure you commit AND push your work to your repository on GitHub.mit.
We will use the state of your repository on GitHub.mit as of 10:00pm on the deadline date.
git push, the continuous build system attempts to compile your code and run a subset of the autograder tests.
You can always review your build results on Didit.
- There is no guarantee that Didit tests will run within any particular timeframe, or at all. If you push code close to the deadline, the large number of submissions will slow the turnaround time before your code is examined.
- If you commit and push right before the deadline, the Didit build does not have to complete in order for that commit to be graded.
- Passing some or all of the public tests on Didit is no guarantee that you will pass the full battery of autograding tests — but failing them is almost sure to mean lost points on the problem set.