EGRE 245 Programming Project #7 Turtle Graphics solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (8 votes)

The Logo programming language made the concept of turtle graphics famous. Imagine a
mechanical turtle that walks around a board under the control of a C program. The turtle
holds a pen in one of two positions, up or down. While the pen is down the turtle traces
out lines or shapes as it moves; while the pen is up, the turtle moves about freely without
writing anything. In this program you’ll simulate the operation of the turtle and create a
computerized sketchpad as well.
Use a 25 ⇥ 25 board which initially has no marks on it. The turtle always starts at position
(0,0) (row first, then column; position (0,0) is the upper left corner of the board) facing east
with its pen up. The turtle will also always be facing one of four directions – north, south,
east, or west (with north being up on the screen, east to the right, etc.). Your turtle will
then be given a set of commands (as integers) that will control its movement and drawing
on the board. Here are the possible commands:
Command Meaning
1 pen up
2 pen down
3 turn right 90
4 turn left 90
5 x move forward x spaces
6 output the board
9 end of data
Note that the turtle can only move to the edge of the board, e.g. if a move command calls
for moving 5 spaces and after moving only 3 spaces the turtle is at the edge of the board,
it stops and does not complete the remaining 2 moves. Also note that when a pen down
command is given the current location of the turtle should be marked.
2 Program Design
You must subdivide your program so that each command (pen up, pen down, turn right,
turn left, move forward, and output the board) is executed in your code by calling a separate
function. The only global variables you are allowed are for the current board position of the
turtle, whether the pen is up or down, which direction the turtle is facing, and the board (a
two dimensional array).
1
3 Input & Output
All input should come from standard input (which normally would come from a file redirected
on the command line). You may assume that the input is correct. Output should be directed
to standard output and only be produced when the output the board command is given.
You must output your board exactly as it appears in the sample run below.
4 Sample Run
The sample run below was produced with the following data:
5 2
3
5 2
4
2
5 5
3
5 5
3
5 5
3
5 5
6
9
2
5 Deliverables
Name your source code file proj7XXXX.c where XXXX is the last 4 digits of your student
id number. For example, if your student id number is V12345678, your file will be named
proj75678.c. Document your code in the manner discussed in class, and submit your project
in the usual way via the web using the link o↵ of the class web page.
Due date: Thursday, April 16
3