$ bundle
$ ruby run.rb
- Draw a canvas, giving x and y dimensions:
enter command: C 20 4
______________________
| |
| |
| |
| |
----------------------
- Draw a line, giving xy coordinates of start and finish.
enter command: L 1 2 6 2
______________________
| |
|xxxxxx |
| |
| |
----------------------
- Draw a rectangle, giving xy coordinates of top-left and bottom-right.
enter command: R 16 1 20 3
______________________
| xxxxx|
|xxxxxx x x|
| xxxxx|
| |
----------------------
- Fill with a given 'colour' from an xy coordinate.
enter command: B 10 3 o
______________________
|oooooooooooooooxxxxx|
|xxxxxxooooooooox x|
|oooooooooooooooxxxxx|
|oooooooooooooooooooo|
----------------------
- Quit.
enter command: Q
$ rspec
At the outset I chose to model the grid as a 2D array. This worked well until I wanted to implement the fill tool, which seemed to require a more graph-like data structure where each node is able to query the nodes around it. I briefly experimented with such a data structure but ultimately decided against it. Unfortunately this meant that the Fill
shape needs to have access to the canvas to ensure it doesn't modify already-filled points.
I wanted to entirely decouple the Draw program from the means by which the user would enter input. I have done this using a CLI class that parses commands and arguments and calls the Draw program.