Toylogo: CS 475: Computer Graphics - Assignment 1 Due Date: 17/8/2009
Toylogo: CS 475: Computer Graphics - Assignment 1 Due Date: 17/8/2009
Toylogo: CS 475: Computer Graphics - Assignment 1 Due Date: 17/8/2009
1 Introduction
Turtle graphics is a style of computer drawing where a the drawing cursor
is imagined to be turtle who carries a pen. The turtle has a preserved state
(position and orientation) and can perform a small number of operations
against that state (move forward, move back. turn left, turn right). While
these operations are performed the pen is used to plot 2D drawings on a
drawing canvas (which is essentially a part of the 2D plane).
The turtle thus consists of:
1. A position
2. An orientation
The turtle moves with commands that are relative to its own current
position, such as move forward 10 units and turn left 90 degrees. The
turtle can also move without drawing, as if the pen is held up. It is
possible to understand (predict and reason about) the turtles motion by
imagining what they would do if they were the turtle. Seymour Papert (the
inventor of the LOGO programming language) called this body syntonic
reasoning.
Turtle graphics was the model used in the very popular LOGO pro-
gramming language. In this assignment you will implement an interpreter
for toy version of the LOGO language called ToyLOGO and use that to
create interesting 2D drawings and animations.
2 ToyLOGO Definition
The turtle can move forward and backward, turn left or right. The current
turtle position can also be set without drawing.
We define the ToyLOGO command set that the interpreter should un-
derstand is as follows.
1
1. Begin a ToyLOGO program.
Syntax: BEGIN
5. Move the turtle in the forward direction by dist units and draw a line
as the turtle moves.
Syntax: F dist
6. Move the turtle in the backward direction by dist units and draw a
line as the turtle moves.
Syntax: B dist
9. Move the turtle in the forward direction by dist units without drawing.
Syntax: MF dist
10. Move the turtle in the backward direction by dist units without draw-
ing.
Syntax: MB dist
11. Change the current drawing color to ( r, g, b). Red, Green and Blue
values range from 0.0 to 1.0.
Syntax: COL (r, g, b)
12. Change the current background color to ( r, g, b). Red, Green and
Blue values range from 0.0 to 1.0.
Syntax: BGCOL (r, g, b)
14. End of a repeat block. All commands between REPEAT and EN-
DREP are repeated. Nested REPEATs are allowed.
Syntax: ENDREP
2
15. Scale the drawing canvas uniformly by a factor of s. The original
coordinate system on the drawing canvas ranges from 1 x 1 and
1 y 1. The origin is at the center of the canvas. This is at the
default scale 1.0. This means that all values given to F, B, MF and
MB will lie inside the canvas if they are in this range. Scaling can help
increase or decrease this range. Note that this scaling is independent
of window size.
Syntax: SCALE s
3 ToyLOGO Examples
1. Example 1: Here are two ways to write a program to generate a square.
BEGIN
CLS
RESET BEGIN
F 0.2 CLS
R 90 RESET
F 0.2 REPEAT 4
R 90 F 0.2
F 0.2 R 90
R 90 ENDREP
F 0.2 END
R 90
END
2. Example 2: This program rotates a square about its center.
BEGIN
CLS
RESET
REPEAT 36
REPEAT 4
F 0.4
R 90
ENDREP
R 10
ENDREP
END
3. Example 3: These two programs produce output that looks the same.
3
BEGIN
BEGIN
CLS
CLS
RESET
RESET
SCALE 100
REPEAT 36
REPEAT 36
REPEAT 36
REPEAT 36
F 0.05
F 5
R 10
R 10
ENDREP
ENDREP
R 10
R 10
ENDREP
ENDREP
END
END
4 The Assignment
Given:
A skeleton OpenGL application source code that will execute the com-
mands to generate the drawings (toylogo.cpp).
The Makefile can be called to compile the application program.
To do:
1. A skeletal turtle class (turtle t)is given. You have to implement the
various functions in this class. Note that, the interpreter has already
been implemented. The parser converts the ToyLOGO program to a
list of commands. The application goes through this list and executes
every command, using the exec(..) function in the turtle t class.
In order to do this you have to modify the turtle.cpp file. The
assignment can be completed without any change to the class signature
given (i.e., only the function bodies have to be filled out).
4
3. The assignment will be marked as follows:
BEGIN
CLS
RESET
REPEAT 36
REPEAT 4
F 0.2
R 90
ENDREP
CLS
R 10
PAUSE 10
ENDREP
5
drawing of your choice that uses variables and/or recursion. Some
such examples are:
Various kinds of spirals
Lindenmayer systems
Sierpinski triangle
To Submit:
2. A html report page on the assignment that should contain some de-
tails about what you implemented and images of the results that you
generated.