Growing up, my first console game system was an Atari 2600 and I will always have a love for some of those games I so enjoyed as a child. Many of the graphics are still memorable, perhaps even iconic.
It turns out that these sprites are very simplistic bitmaps, 8 pixels wide with variable height where the binary representation is the arrangement of the pixels.
For example, the hex bytes 0x18, 0x24, 0x18 would draw a crude circle like so:
0x18: 00011000
0x24: 00100100
0x18: 00011000
As 8 pixels wide creates fairly small graphics (even by Atari 2600 standards) it was common to double or quadruple either the height, width or both to create a larger (though more blocky and distorted) version of the same image. They would commonly also be flipped vertically or horizontal for both player sprites and playfields. The game Combat is a good example of this.
The challenge is, to write code to display these sprites as "graphics" in ASCII form including the ability to stretch or flip them vertically, horizontally or both. This must be in the form of either a full program, or callable function.
Input:
- An array of bytes, each representing the horizontal bits for that line.
- A non-zero integer value for each direction, horizontal and vertical representing the scaling factor for that dimension.
- A negative value indicates that the dimension should also be flipped along it's axis.
Output:
- ASCII representation to STDOUT or a newline-separated string, using a space character for black (0) pixels and any printable, non-space character of your choice for white (1) pixels.
Test data:
bmp1 = [ 0x06, 0x0F, 0xF3, 0xFE, 0x0E, 0x04, 0x04, 0x1E, 0x3F, 0x7F, 0xE3, 0xC3, 0xC3, 0xC7, 0xFF, 0x3C, 0x08, 0x8F, 0xE1, 0x3F ]
bmp2 = [ 0x07, 0xFD, 0xA7 ]
bmp3 = [ 0x00, 0x8E, 0x84, 0xFF, 0xFF, 0x04, 0x0E, 0x00 ]
bmp4 = [ 0x00, 0xFC, 0xFC, 0x38, 0x3F, 0x38, 0xFC, 0xFC]
Note: Above example input arrays of bytes are provided as hex. If your platform does not accept hex literals for byte representation you may convert them to a native byte-equivalent literal.
Example Output:
f( bmp1, 1, 1 ) =>
--------
XX
XXXX
XXXX XX
XXXXXXX
XXX
X
X
XXXX
XXXXXX
XXXXXXX
XXX XX
XX XX
XX XX
XX XXX
XXXXXXXX
XXXX
X
X XXXX
XXX X
XXXXXX
--------
f( bmp1, -2, 1 ) =>
----------------
XXXX
XXXXXXXX
XXXX XXXXXXXX
XXXXXXXXXXXXXX
XXXXXX
XX
XX
XXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXXX
XXXX XXXXXX
XXXX XXXX
XXXX XXXX
XXXXXX XXXX
XXXXXXXXXXXXXXXX
XXXXXXXX
XX
XXXXXXXX XX
XX XXXXXX
XXXXXXXXXXXX
----------------
f( bmp2, 1, 2 ) =>
--------
XXX
XXX
XXXXXX X
XXXXXX X
X X XXX
X X XXX
--------
f( bmp2, 2, 1 ) =>
----------------
XXXXXX
XXXXXXXXXXXX XX
XX XX XXXXXX
----------------
f( bmp2, -2, -2 ) =>
----------------
XXXXXX XX XX
XXXXXX XX XX
XX XXXXXXXXXXXX
XX XXXXXXXXXXXX
XXXXXX
XXXXXX
----------------
f( bmp3, 1, -1 ) =>
--------
XXX
X
XXXXXXXX
XXXXXXXX
X X
X XXX
--------
f( bmp3, 3, 3 ) =>
------------------------
XXX XXXXXXXXX
XXX XXXXXXXXX
XXX XXXXXXXXX
XXX XXX
XXX XXX
XXX XXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXX
XXX
XXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
------------------------
f( bmp4, -1, -1 ) =>
--------
XXXXXX
XXXXXX
XXX
XXXXXX
XXX
XXXXXX
XXXXXX
--------
f( bmp4, 4, 2 ) =>
--------------------------------
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXX
--------------------------------
Note: the horizontal lines above and below are to show the beginning and end of the output. They are not required in the output, however empty lines (represented by all zeros/spaces) at the beginning and/or end are required, as shown.
Note 2: these test bitmaps were inspired by and re-drawn/coded based on game screenshots tagged as "fair use" on Wikipedia.