An ASCII drawing tool that supports bucket fill.

dyurk 801b29901e Renaming example files for clarity 2 years ago
README.md c7caa252c8 Update 'README.md' 2 years ago
drawT00L.rb 86ceec17d4 Initial commit 2 years ago
input_example.txt 801b29901e Renaming example files for clarity 2 years ago
output_example.txt 801b29901e Renaming example files for clarity 2 years ago

README.md

DrawT00L

An ASCII drawing tool that supports bucket fill.


DrawT00L creates drawings by coordinates from a provided input file. drawT00L.rb takes two arguments, path to input file and path to the output file. Before starting to "draw", the program checks that two arguments are provided (input/output files), it also guards against running without providing arguments.

There are four core methods:

canvas which takes two parameters (width / height). It will update the @paper array with the top, bottom and side borders, while filling each empty place of the canvas with a space.

create_line which handles the creation of vertical and horizontal lines. The method checks for matching x and y pairs to determined the location and type of the line. Between the starting and end location, each placement is replaced with "x".

create_rectangle makes use of the create_line method to build all 4 sides of the rectangle.

bucket_fill grabs the character found in the supplied coordinates to match against its surroundings. An empty array (area_fill) is used to start checking for all candidates to be filled. As coordinates are checked they are removed from the area_fill array. On each while loop, surrounding coordinates are updated in the array covering all directions: top , bottom , left ,right.

The read_input is a simple method to handle reading each line to gather instructions. The write_output method writes to the output file on each instruction. Everything is executed inside a begin block, this allows clean handling of exceptions.