Question
*/ #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
return; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started