8.15.0.6

B — GUI🔗

Due Tuesday 17 September 2024, 11:59pm

Purpose T to explore the GUI libraries of your chosen programming language, and optionally, to figure out command-line arguments

When developers deal with with geometric ideas, such as those in a board game, investing a bit of time into visualization support pays off handily. It tends to be much easier to understand a visualized test scenario than one that is presented in plain text.

Delivery You must deliver xgui in a directory called B in your repository.

All auxiliary files must be put into a sub-directory called B/Other/.

Task Develop xgui, a program that processes an arbitrarily long stream of JSON objects from STDIN. Each object has the following shape:

      { "x" : Dim, "y" : Dim, "color" : Color }

      INTERPRETATION computer-graphics placement coordinates for a colored disk

    

    where

     Dim is one of: 0, 1, 2;

     Color is one of: red, white, blue, green, yellow.

xgui creates an image of a grid of 3 x 3 squares, some filled with colored disks, some left blank. Each of the objects specifies which of the squares is filled with what kind of colored disk if any. If several objects in the stream point to the same square, the last one of this kind defines how the circle is painted.

xgui saves a PNG version of this image in a file named the-image.png.

xgui outputs an object whose keys are color strings and whose values are the number of times this color appeared in the input stream. It does not count colors that do not occur in the input stream.

Well-formed and Valid You may assume that all inputs to your test harnesses from STDIN are well-formed and valid. A well-formed piece of JSON satisfies the grammar; such a piece is valid if it also satisfies all the side constraints of a schema specification.

For example, if the input stream contains the following JSON value

    {"color":"red","x":1,"y":0}

    {"color":"white","x":0,"y":1}

    {"color":"blue","x":2,"y":1}

the program would save the following image in the-image.png :

Its output would be {"blue":1,"red":1,"white":1} .

Your program’s rendering of the various shapes and colors must be such that a user of xgui can easily correlate the visual appearances with the specification. Otherwise you may use your imagination.

Optional If given "--show" (two dashes!) on the command line, your program also opens a window, renders the grid in the window, and waits for a mouse click.

You will want to run xgui with "--show" only on your own development laptop.