YCP Logo Lab 22: Display Hack

Due: Monday, Oct 27 by 11:59 PM

Getting Started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download CS200_Lab22.zip. Import it into Visual Studio (File->Import...).

Add your code to the source file called Draw.c.

Your Task

In this lab, you will implement a function called draw_rectangle, which draws a rectangle on the screen using text characters.

The draw_rectangle function has three parameters:

  • struct rect r - describes the rectangle to be drawn
  • int fg_color - the foreground character to use when drawing the rectangle
  • int bg_color - the background character to use when drawing the rectangle

struct rect contains the following fields:

  • int top_row - row number of top row of rectangle (row 0 is the top of the window)
  • int bottom_row - row number of the bottom row of the rectangle
  • int left_col - column number of the left column of the rectangle (column 0 is the left of the window)
  • int right_col - column number of the right column of the rectangle

You can draw the rectangle either as a solid block of characters, or you can just draw the outline. You can use any character to print the rectangle.

The file Console.h, under "Header Files" in the Solution Explorer, describes the functions available for you to call.

In order to choose the color of the characters you draw, call the cons_change_color function. This function takes two parameters, representing the foreground and background colors to use.

In order to draw the rectangle at the specified position on the screen, you can call the cons_move_cursor function, which moves the cursor to the specified row and column. The general idea is, for each row of the rectangle, move the cursor to the beginning of the row, and then use cons_printw to draw each character in the row. (This function works exactly like printf.)

Once you have implemented the draw_rectangle function, you can run the program using the already-implemented main function. The program draws a number of random rectangles of different sizes and positions on the screen. When the program finishes, the screen should look something like this:

figures/Rectangles.png

Submitting

When you are done, choose Tools->Submit to submit your completed lab to the server. You will need to enter your Marmoset username and password.

If the Tools->Submit option does not work, create a zip file containing the files in your project, and upload it to the submission server as lab22. The server URL is

https://camel.ycp.edu:8443/