TurtleGraphics 2



Additional Functions:



PenBy(<dx>,<dy>) Walks the turtle from the current position (X,Y) to (X+<dx>, Y+<dY>. If the pen is down, a line is drawn.



PenTo(<x>,<y>) Walks the turtle from the current position to (<x>,<y>). If the pen is down, a line is drawn.



DrawLine(<x0>,<y0>,<x1>,<y1>) Draws a line from (<x0>,<y0>) to (<x1>,<y1>). This does not change the position or direction of the turtle.



DrawBar(<x0>,<y0>,<x1>,<y1>,<density>) Draws a solid rectangle with diagonal line going from (<x0>,<y0>) to (<x1>,<y1>). Use a density of 1 to make the rectangle solid.





CSC103: LAB 5

Due at the start of lab on Friday, October 13th

(Turn in disk and listings)



Part 1



Write a program to imitate the motions of a drunken sailor on the graphics screen. The sailor starts at the center of the screen and randomly takes a step in one of four directions: up, left, down, or right. He keeps doing this until you stop the program with Ctrl-C.



Your program must keep the sailor on the screen. Show each step of the sailor as a square bar of some reasonable size you determine ( 5 works nicely). A step size of 1 does not show well on the screen. Use four different colors to draw the steps. You might make steps going up one color, steps going left a different color, steps going down yet a different color, etc.



Use the project and cpp files prac1.ide and prac1.cpp for this problem.



Part 2



Write a program to create a checkerboard pattern on the screen. The program must ask the user for a height and width. It must then create a checkerboard pattern on the screen using blocks that are of size height by width. The blocks must be at least two different colors. If you use exactly two colors, your screen must resemble a checkerboard.



Use the project and cpp files prac2.ide and prac2.cpp for this problem.