# Computer Engineering - My Class Sites

Document Sample

```					            For this assignment, make a new directory called Assignment3

Theory Questions
Answer the following questions in a Word or WordPerfect document and save it
as Assignment3Theory.

1. What are the two Execution Screen settings we can use in Turing? What the
THREE main differences between the two settings?

Text Mode                                   Graphics Mode
Standard size - 80 columns by 25 rows       Standard size - 640 columns by 400 rows
Origin – Top left                           Origin – bottom left
Screen scrolls with text                    Screen position is fixed.

2. What does the cls command do?
The cls command clears all TEXT off the screen

3. When creating Animations in Turing, how do we control the speed of the
animation?
We control the speed of an animation by change the numerical value in the
delay() command

4. How do we pause our programs waiting for the user to press any key?
We pause until the user hits any key by using the getch(varName) command.

5. Can we change the size of the Execution window? If so, how?

setscreen(“graphics: width; height”) or
setscreen(“text: width; height”)

6. An example of the command to draw a line is: drawline (40, 50, 100, 200, 91).
What does each part of the command do?
i. 40 – x coordinate of first point
ii. 50 - y coordinate of first point
iii. 100 - x coordinate of second point
iv. 200 - y coordinate of second point
v. 91 – integer value of the colour

7. An example of the command to draw a box is: drawfillbox(0, 0, 100, 200, 32).
What does each part of the command do? Does this command create a box that is
long or tall?
i. 0 – x coordinate bottom left corner
ii. 0 - y coordinate of bottom left corner
iii. 100 - x coordinate of top right corner (x + width)
iv. 200 - y coordinate of top right corner (y + height)
v. 32 – integer value of the colour
This command will create a rectangle that is taller then it is long
Page 1 of 6
8. An example of the command to draw an oval is: drawoval (100, 150, 20, 10, 10).
What does each part of the command do? Does this draw an oval or a circle?
How could I change the example to create a circle?

i. 100 – x coordinate the center of the oval
ii. 150 - y coordinate the center of the oval
iii. 20 – radius of the x (horizontal) axis
iv. 10 – radius of the y (vertical) axis
v. 10 – integer value of the colour
This command draws an oval because the x-radius is larger then the y-
radius. To get a perfect circle out of the drawoval command you have to
make the two radius values equal.

9. An example of the command to draw an arc is: drawacr(120, 200, 30, 50, 90,
270, 1) What does each part of the command do? (

i.   120 – x coordinate the center of the arc
ii.   200 - y coordinate the center of the arc
iii.    30 – radius of the x (horizontal) axis
iv.    50 – radius of the y (vertical) axis
v.    90 – starting angle in degrees
vi.    270 – finishing angle in degrees
vii.    1 - integer value of the colour

10. Can I output text in “graphics” mode? Can I set a specific location of this text?
What is the command to do this?

Yes you can put text in graphics mode. To set a specific location in graphics
mode we use the command lovatexy(x, y).
Note: in text mode the command is locate(y,x).

Programming Questions
Read the following questions carefully and create a Turing program that
completes the specifications outlined. Save each file as Assignment3_1,
Assignment3_2, etc. Make sure you include a header for each program describing the
filename, date, your name, and a brief description of what the program is doing. Each
question sound be done individually and saved as a different file.

1. Modify the BrownianMotion program so that you do not erase the image of the
particle each time but leave it as a train when it moves. Change the color of the
trail randomly each time the particle starts at the center. Use a black background.

% Assignment3_1.t

% 1. Modify the BrownianMotion program so that you do
% not erase the image of the particle each time but leave
% it as a train when it moves. Change the color of the
% trail randomly each time the particle starts at the
% center. Use a black background.
Page 2 of 6
colorback (black)
for row : 1 .. maxrow
put repeat (" ", maxcol) ..
end for

% Set character color to magenta
color (magenta)
setscreen ("nocursor") % Hide cursor
loop
% Start at center
var row := maxrow div 2
var column := maxcol div 2
var newcolor:int
loop
% Start over when asterisk goes off the window
exit when column < 1 or column > maxcol
or row < 1 or row > maxrow
locate (row, column)
put "*" ..
delay (100)
% Compute new value for row
randint (row, row - 1, row + 1)
% Compute new value for column
randint (column, column - 1, column + 1)
end loop
randint(newcolor, 0, 255)
color(newcolor)
end loop

2. Write a program to draw a funny face in the window with its center at any point
you specify. Make the face 50 by 50. Arrange so that the color of the face and
the background can be inputted at the same time as you specify its location in the
execution window. Refuse to plot the face if it goes outside the window.

% Assignment3_2.t
/* 2. Write a program to draw a funny face in the
window with its center at any point you specify.
Make the face 50 by 50. Arrange so that the color of
the face and the background can be inputted at the
same time as you specify its location in the
execution window.
*/
setscreen ("graphics")
var x, y, fcolor, bcolor : int
var r : int := 50

% Entering where center of face goes
loop
put "The deminsions of the screen are: (", maxx, ",", maxy, ")"
Page 3 of 6
put " Enter the integer values of:"
put ""
put " x and y coordinates of the center:"
get x, y

exit when x - r > 0 and x + r < maxx and
y - r > 0 and y + r < maxy
put "Values go beyond the range of the screen"
end loop

% Entering what colours are used for background and head
loop
put "the colors of the forground and head between 0 and ", maxcolor
get fcolor, bcolor
exit when fcolor < maxcolor and bcolor < maxcolor
put "values go beyond the range of the computer"
end loop
cls

% draws background
colorback (bcolor)
for row : 1 .. maxrow
put repeat (" ", maxcol) ..
end for

drawfilloval (x, y, r, r, fcolor) % head
drawfilloval (x - 20, y + 20, 10, 10, blue) % left eye
drawfilloval (x + 20, y + 20, 10, 10, blue) % right eye
drawfilloval (x, y, 10, 15, blue) % nose
drawfillarc (x, y - 20, 30, 15, 180, 0, blue) % mouth

3. Ask the user for the upper-left row and column and the bottom-right row and
column to represent the top left and bottom right corners of a rectangle. Ask the
user which character they would like the rectangle to be created with. Create the
outline of the rectangle from the top-left corner to the bottom right corner given
by the user in the character they indicate without using the drawbox command. (

% Assignment3_3.t
/*
3.   Ask the user for the upper-left row and column
and the bottom-right row and column to represent
the top left and bottom right corners of a
rectangle. Ask the user which character they
would like the rectangle to be created with.
Create the outline of the rectangle from the
top-left corner to the bottom right corner given
by the user in the character they indicate without
using the drawbox command.
*/
Page 4 of 6
var ulx,uly,brx,bry:int
var shape:string
put "for the values entered, please make sure they are between:"
put "0 and ", maxcol, " for columns and 0 and ", maxrow, " for rows"
put "please enter the upper-left Y and X row and column values"
get uly, ulx
put "please enter the bottom-right Y and X row and column values"
get bry, brx
get shape
cls

%left side
for ls: uly..bry
locate (ls, ulx)
put shape ..
end for

%right side
for ls: uly..bry
locate (ls, brx)
put shape ..
end for

%top line
for tcol: brx..ulx
locate (uly, tcol)
put shape
end for

%bottom line
for bcol: brx..ulx
locate (bry, bcol)
put shape ..
end for

4. Draw an arrow on the bottom left of the window using drawlines. The point of
the arrow should face right. Have the arrow move across the window from left to
right using the delay to control the speed. Once the arrow is off the window,
make it appear on the bottom right corner with the point facing left. Make your
arrow now go from right to left. Now make your program loop forever, have the
arrow moving back and forth across the screen.

% Assignment3_4.t
/*4.      Draw an arrow on the bottom left of the window
using drawlines. The point of the arrow should face
right. Have the arrow move across the window from
left to right using the delay to control the speed.
Once the arrow is off the window, make it appear on
the bottom right corner with the point facing left.
Page 5 of 6
Make your arrow now go from right to left. Now make
your program loop forever, have the arrow moving back
and forth across the screen.
*/
loop
% left to right
for x : 0 .. maxx
drawline (x, 10, x + 50, 10, blue) %straight part
drawline (x + 50, 10, x + 40, 15, blue) % top arrow part
drawline (x + 50, 10, x + 40, 5, blue) % top arrow part
delay (5)
drawline (x, 10, x + 50, 10, white) % erase straight part
drawline (x + 50, 10, x + 40, 15, white) % erase top arrow part
drawline (x + 50, 10, x + 40, 5, white) % erase top arrow part
end for

% right to left
for decreasing x : maxx .. 0
drawline (x, 10, x - 50, 10, blue) %straight part
drawline (x - 50, 10, x - 40, 15, blue) % top arrow part
drawline (x - 50, 10, x - 40, 5, blue) % top arrow part
delay (5)
drawline (x, 10, x - 50, 10, white) % erase straight part
drawline (x - 50, 10, x - 40, 15, white) % erase top arrow part
drawline (x - 50, 10, x - 40, 5, white) % erase top arrow part
end for
end loop

Page 6 of 6

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 4 posted: 4/6/2013 language: English pages: 6