Programming Assignment 1: Turtle Graphics: Due: 11:59pm, Thursday, October 9
Programming Assignment 1: Turtle Graphics: Due: 11:59pm, Thursday, October 9
Overview
You will use simple turtle graphics to create a three-line drawing consisting of the following text, where XX should be
replaced with the two letters from your own CS11 login id:
CS11FXX
FALL
2014
Setup
Open a new Linux terminal window. In your home directory, create/make a new directory called pa1 (mkdir) and go
(change directory - cd) into that directory (in Unix, the tilde ~ expands to your home directory):
mkdir ~/pa1
cd ~/pa1
Copy the turtleClasses.jar file from the public directory that will provide the drawing environment for this
assignment. Notice the single dot at the end of this command. The single dot means your current working directory,
which is your pa1 after you executed the cd command above. The dot dot means the parent directory (one up).
cp ~/../public/turtleClasses.jar .
Instructions
You should create a Java file called CS11Turtle.java under your ~/pa1 directory. This is the only file that needs to
be turned in with this assignment. This file will contain all the Java code that will run your program. Use vim or gvim to
edit the file. We will not be using any IDEs, like DrJava or Eclipse for this class. (It is your responsibility to make sure all
your programs compile on the lab computers.)
To compile your code, use the following command at the Linux command line prompt (-cp is short for -classpath):
Your code will use classes from turtleClasses library including classes World and Turtle. World is the drawing
canvas and Turtle is the "pen" that will do the drawing. Turtle extends SimpleTurtle, which is another class in
turtleClasses. You will only be dealing with methods of SimpleTurtle to do all of your drawing. The Javadoc
API for this class SimpleTurtle, and other classes in turtleClasses, can be accessed by the appropriate link in
the Useful Links section of the class home page. You should definitely take a look at the API for SimpleTurtle as all
the needed drawing methods are covered there. Note on the SimpleTurtle methods turnLeft and turnRight:
these methods do not make the turtle face in the left or right direction. Rather, they rotate the turtle 90 degrees
counterclockwise or clockwise, respectively.
Use the code at the end of this write-up as a starting point for CS11Turtle.java. The code for drawing the letter 'C'
in CS11FXX is provided for you. Do not change the size of 600x400 pixels for the World. Each character should be
drawn 40 pixels wide and 80 pixels high. There should be 40 pixels of space between each character and between each
line of text. The first letter, 'C', is positioned so that its top-left corner is at the position (10, 10). Use constants defined.
Here is an example of how the final image should look using the login cs11fxx:
Remember: Use your own login id instead of CS11FXX. As in the template provided, you should write additional
methods to draw the other characters in the text and call these methods from main(). Note: if a particular character
appears multiple times in the text (such as '1' in CS11 and in 2014), do NOT write separate methods for each instance of
the character. Use just one method and pass in the appropriate x and y values to the method. These x and y coordinates
should correspond to the top-left corner of the bounding box for the drawn character.
Use the code given for 'C' as a guide for drawing the other letters, but feel free to use other methods from
SimpleTurtle that you may find useful. One method in particular you may find useful to draw line segments at an
angle (such as the at the top of '1') is turn(), which turns the turtle by a specified number of degrees. There is no
specific, required style to draw your letters. As long as it can be clearly understood what each character actually is and
the width and height requirements are observed, you are free to get creative.
1) Draw the text so that it is centered both vertically and horizontally in the 600x400 World, as in the example
below. And,
2) Add something creative and unique. You can change the colors, draw stars and robots, add highlighting, etc.
Style Requirements
You will be graded for the style of programming on this assignment. A few suggestions/requirements for style are given
below. These guidelines for style will have to be followed for all the remaining assignments. Read them carefully. In the
template code provided below for this assignment, all of these requirements are met (replace comments appropriately).
● Use reasonable comments to make your code clear and readable.
● Use class header and method header block comments to describe the purpose of your program and methods
(see below).
● Use reasonable variable names that are meaningful.
● Use static final constants to make your code as general as possible. No hardcoding constant values inline.
● Judicious use of blank spaces around logical chunks of code makes your code much easier to read and debug.
● Keep all lines less than 80 characters. Use 2-3 spaces (not tabs) for each level of indentation. Make sure each
level of indentation lines up evenly.
● Every time you open a new block of code (use a '{'), indent farther. Go back to the previous level of indenting
when you close the block (use a '}').
● Always recompile and run your program right before turning it in, just in case you commented out some code by
mistake.
Turnin Instructions
Remember the deadline to turn in your assignment is Thursday, October 9, by 11:59pm.
Make sure the program works correctly in your cs11f login on the workstations in the labs in the basement of the CSE
building when the workstations are booted under Linux.
When you are ready to turn in your program in, type in the following command and answer the prompted questions
turnin pa1
verify pa1
/*
* Name: Jane-Joe Student <<< --- Replace with Your Name
* Login: cs11fXX <<< --- Use your cs11f course-specific account name
* Date: Month Day, Year
* File: Name of this file, for example: CS11Turtle.java
* Sources of Help: ... (for example: names of people/tutors/students, books, websites, etc.)
*
* Describe what this program does here.
*/
import turtleClasses.*;
import java.awt.Color;
/*
* Name: Class name
* Purpose: Briefly describe the purpose of this class
*/
private final static int START_X_1 = 10; // starting x offset for line 1
private final static int START_X_2 = 10; // starting x offset for line 2
private final static int START_X_3 = 10; // starting x offset for line 3
private final static int START_Y = 10; // starting y offset
/*
* Delay between turtle actions (turns, moves) in milliseconds.
* 1000 = 1 sec. so 200 = 0.2 sec.
*/
private final static int DELAY = 200;
/*
* Name: Constructor name
* Purpose: Briefly describe the purpose of this constructor
* Parameters: List all parameters and their types and what they represent.
* If no parameters, just state None.
*/
/*
* Name: Method name
* Purpose: Briefly describe the purpose of this method
* Parameters: List all parameters and their types and what they represent.
* If no parameters, just state None.
* Return: Specify the return type and what it represents.
* If no return value, just specify void.
*/
/*
* Name: Method name
* Purpose: Briefly describe the purpose of this method
* Parameters: List all parameters and their types and what they represent.
* If no parameters, just state None.
* Return: Specify the return type and what it represents.
* If no return value, just specify void.
*/
/* TODO: Add any remaining methods to draw all the other characters */
/*
* Name: Method name
* Purpose: Briefly describe the purpose of this method
* Parameters: List all parameters and their types and what they represent.
* If no parameters, just state None.
* Return: Specify the return type and what it represents.
* If no return value, just specify void.
*/
int x, y;
myTurtle.setPenWidth(PEN_WIDTH);
myTurtle.setPenColor(PEN_COLOR);