P006 -- Graphical Editor

Please restrict discussions in this forum to project related topics.

P006 -- Graphical Editor

Postby DrJump » Thu Sep 09, 2010 5:43 pm

Popularity: B
Success rate: low
Level: 1

Graphical editors such as Photoshop allow us to alter bit-mapped images in the same way that text editors allow us to modify documents. Images are represented as an M x N array of pixels, where each pixel has a given color.

Your task is to write a program that simulates a simple interactive graphical editor.

The input consists of a sequence of editor commands, one per line. Each command is represented by one capital letter placed as the first character of the line. If the command needs parameters, they are given on the same line separated by spaces.

Pixel coordinates are represented by two integers, a column number between 1...M and a row number between 1...N, where 1<=M,N<=250. The origin sits in the upper-left corner of the table. Colors are specified by capital letters.

The editor accepts the following commands:
Code: Select all
I M N                 Create a new M x N image with all pixels initially colored
                      white (0)

C                     Clear the table by setting all pixels white (0).  The size
                      remains unchanged.

L X Y C               Color the pixel (X, Y) in color (C)

V X Y1 Y2 C           Draw a vertical segment of color (C) in column X, between
                      the rows Y1 and Y2 inclusive.

H X1 X2 Y C           Draw a horizontal segment of color (C) in the row Y,
                      between the columns X1 and X2 inclusive.

K X1 Y1 X2 Y2 C       Draw a filled rectangle of color C, where (X1, Y1) is the
                      upper-left and (X2, Y2) is the lower right corner.

F X Y C               Fill the region R of with the color C, where R is defined as
                      follows.  Pixel (X,Y) belongs to R.  Any other pixel which
                      is the same color as pixel (X, Y) and shares a common side
                      with any pixel in R also belongs to this region.

S Name                Write the file name in MSDOS 8.3 format followed by the
                      contents of the current image.

X                     Terminate the session.

On every command S Name, print the filename NAME and contents of the current image. Each row is represented by the color contents of each pixel. See the sample output.

Ignore the entire line of any command defined by a character other than I, C, L, V, H, K, F, S and X, and pass on to the next command. In case of other errors, the program behavior is unpredictable.

Sample Input
Code: Select all
I 5 6
L 2 3 A
S one.bmp
G 2 3 J
F 3 3 J
V 2 3 4 W
H 3 4 2 Z
S two.bmp

Sample Output
Code: Select all
Posts: 19
Joined: Sun Mar 07, 2010 6:08 pm

Re: P006 -- Graphical Editor

Postby RJDavis » Tue Sep 14, 2010 2:50 pm

I've been working on this problem and I have all of the functions working except for F X Y C. I don't understand what they want me to do. Am I supposed to use X Y as the starting point for region R and then make the adjacent pixels the same color as C?
Posts: 1
Joined: Sat Sep 11, 2010 11:52 am

Re: P006 -- Graphical Editor

Postby Ted J. » Wed Sep 15, 2010 1:30 pm

RJ, I think this is just your standard "flood fill" feature, so you are pretty close.

This is my take...

1. You start with the pixel at X Y and note it's original color.
2. Note all adjacent same-as-original colored pixels
3. Fill X Y with new color
4. For each of the adjacent same-as-original pixels, loop step 2-4
5. You're done when you end up with no adjacent pixels that match the original color
Ted J.
Posts: 10
Joined: Sun Mar 07, 2010 5:40 pm

Return to Problems

Who is online

Users browsing this forum: No registered users and 1 guest