Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*/ #include imgUtils.c // This lets the driver code override the image size if it needs to. Make sure // you don't hard-code these values

*/ #include "imgUtils.c"

// This lets the driver code override the image size if it needs to. Make sure // you don't hard-code these values anywhere! #ifndef SIZEX #define SIZEX 512 #define SIZEY 512 #endif

/*---------------------------------------------------------------------------*/

/** * This struct contains one node of the linked list, which represents a single * command to the Turtle. It's field should include: * * - cmd : A char array of size 10 holding the command name * * - val : An integer that stores a parameter for the command (like forward, * backward and colour). * * - next : A pointer to a struct of the same type, this is used for the * linked list * * TODO: Complete this struct definition ****/

typedef struct cmdnode {

} CmdNode;

CmdNode *deleteCommand(CmdNode *head, int cmdNum) { /** * This function deletes the node from the linked list that corresponds to * the line number cmdNum. If there is no command with the given cmdNum, then * the function does nothing. * * Returns a pointer to the head of the linked list (which may have changed * as a result of the deletion) * * TODO: Implement this function */

return NULL; }

/*---------------------------------------------------------------------------*/

CmdNode *deleteCommandList(CmdNode *head) { /** * This function deletes the linked list of commands, releasing all the * memory allocated to the nodes in the linked list. * * Returns a NULL pointer so that the head of the list can be set to NULL * after deletion. * * TODO: Implement this function */

return NULL; }

/*---------------------------------------------------------------------------*/

void run(Image *im, CmdNode *head, int *endX, int *endY) { /** * This function runs the list of commands to move the turtle around and draw * the image, and returns the final position of the turtle in the variables * endX and endY. * * -------------------------------------------------------------------------- * * NOTE: In the image we work with, the top-left pixel is (0,0), * - x increases as you go right, up till SIZEX-1 * - y increases as you go down, up till SIZEY-1 * * (0,0) (SIZEX-1, 0) * x------------------------x * | | * | | * | | * | | * | IMAGE | * | | * | | * | | * | | * | | * x------------------------x * (0, SIZEY-1) (SIZEX-1, SIZEY-1) * * The image is in grayscale (black and white), so the colours are numbers * from [0-255] where 0 is black, 255 is white, and the values in between * are varying levels of gray. * * You need to understand how the (x,y) values are stored so you know how * they should be updated when you move (down means y increases, etc). You do * not need to use the 'im' variable for anything other than passing it into * the drawLine() function described below. * * -------------------------------------------------------------------------- * * Here's the setup - There is a turtle (with a pen) that walks along the * image. When the pen is down (on the paper), it draws a line along the path * that it walks on. (If you want to play around with this, consider looking * at the `turtle` library in python!) * * The turtle initially starts at pixel (0, 0) [at the top left], * facing right (in the positive x direction). The pen starts off * as `down`, with the default colour being black (0). * * You need to go through the linked list and 'run' the commands to keep * track of the turtles position, and draw the appropriate lines. Here is * what each command should do: * * - penup : Put the pen up (stop drawing) * - pendown : Put the pen down (start / continue drawing) * - colour : Draw lines in colour from now on * - forward : Move the turtle forward steps (pixels) * in the direction it is facing. * - backward : Same as above, except move backwards * - right : Turn the turtle to the right by 90 degrees * - left : Turn the turtle to the left by 90 degrees * * NOTE: Make sure that you do *not* go outside the image. For this, set the * maximum and minimum values of x and y to be 0 and SIZEX-1 / SIZEY-1 * respectively. * * For instance, if the turtle is at (0,0) facing right, and your command is * `forward 100000`, it will only go forward till (SIZEX-1, 0), and end * up at the rightmost pixel in that row. * * IMPORTANT: Once you are done with all the commands, make sure you save the * final (x,y) location of the turtle into the variables endX and endY. * * -------------------------------------------------------------------------- * * We have already implemented a drawLine() function (in imgUtils.c) which * you should use to actually draw the lines. It takes in the following: * * - a pointer to an image struct (use 'im') * - (x,y) location of start point * - (x,y) location of end point * - a colour to draw the line in [0-255] * * Note that this function only draws horizontal and vertical lines, so * either the x values or the y values of both points must be the same. * Both these points *must* also be within the image. * [ 0 <= x < SIZEX, 0 <= y < SIZEY ] * * * TODO: Implement this function */

return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago