Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a simple logo/turtle emulation program. The program will read in a file containing a logo (like) program consisting of the commands FORWARD, JUMP, RIGHT,
Write a simple logo/turtle emulation program. The program will read in a file containing a logo (like) program consisting of the commands FORWARD, JUMP, RIGHT, LEFT and REPEAT. The name of the file will be passed to your program as a command line argument. Your program should load this file into memory then produce the corresponding line drawing. i.e. it should not repeatedly open and read the file every time the scene is drawn but once, before entering into the drawing loop. The four logo instructions control the motion of the cursor on the screen and can be used to form pictures. The command FORWARD X will move the cursor forwards from its current position by X units drawing a straight line of X units long. RIGHT X will rotate the cursor to the right by X degrees, LEFT X rotates left by X degrees. JUMP has the effect of lifting the cursor off the screen and moving it forward by X units without leaving a line. REPEAT X [ ] repeats the instructions within the square brackets X times. Assume that the cursor begins in the middle of the screen pointing right, so that initially forwards means towards the right of the screen. For example, the following programme draws the figure to the right, each FORWARD command draws a line 1 unit in length, the LEFT 90 rotates the cursor by 90 degrees so each line forms the sides of a square. FORWARD 1 LEFT 90 FORWARD 1 LEFT 90 FORWARD 1 LEFT 90 FORWARD 1 The REPEAT command can be used to execute a block of commands within square brackets [] multiple times, so the following code produces the corresponding figure. REPEAT 4 [ FORWARD 1 LEFT 90 ] And REPEAT 10 [ FORWARD 0.5 LEFT 10] Loops can also be nested, giving spectacular results, see below REPEAT 36 [ RIGHT 10 REPEAT 360 [ FORWARD .04 RIGHT 1 ] ] You can use these examples above to test your program as it should reproduce the corresponding image. Additional unseen files will be used in assessing whether your program operates correctly. You MUST therefore ensure that you use command line arguments in your program to load the text file. You\'ll be glad to know that you are not expected to build your graphics application from scratch and a sample application has been assembled to simplify the use of graphics. Please copy it to a local directory and compile it. The program uses openGl and glut, although these have been hidden away as much as possible so should not concern you. Should you wish to develop upon another platform you will need to install glut to use the sample code. We will not be able to offer support for working on other platforms. To ensure that your code integrates correctly with the baseline system, avoid making changes outside these sections. To implement the different command objects, at least one teammember will need to know some basic openGl commands. These are: glBegin(GL_LINE_LOOP); glVertex3f( 0.0f, 0.0f, 0.0f); // Start glVertex3f(1.0f,0.0f, 0.0f); // End glEnd(); This draws a single line of one unit in length to the right of the current cursor position. glTranslatef(1,0,0) translates the cursor on the screen one unit to the right from the current position. glRotatef(angle, 0,0,1) rotates the cursor by the desired angle (in degrees) to the left. You shouldn\'t need to know anything more about OpenGl and rendering than that but should you wish, more details can be found here. Note that OpenGl is primarily concerned with 3D graphics but as our logo interpreter will only be drawing in 2D the z-component for glVertex3f and glTranslatef commands will always be zero. ___________________________________________________________________________ Design The design of the system to be built is illustrated in the following UML diagram. A single abstract base class Command has already been provided. Five derived classes (Repeat, Forward, Jump, Left, Right) need to be implemented. This includes their run functions (many of which need to contain the appropriate openGL commands) and their input stream operators. Finally, the Program class needs to be implemented. This class contains a polymorphic vector of pointers to various Command objects which must be filled by the input stream operator, and iterated over within the run function As indicated by the green boxes, this design is split into three sections: 1. The Program class 2. The Repeat class 3. The Forward, Jump, Left and Right classes Mmm mmmmmm zoos
Attachments:
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