长大后,我的第一个主机游戏系统是Atari 2600,我将永远爱上我小时候喜欢的一些游戏。许多图形仍然令人难忘,甚至具有标志性。
事实证明,这些子画面是非常简单的位图,宽度为8个像素,高度可变,其中二进制表示形式是像素的排列。
例如,十六进制字节0x18、0x24、0x18将绘制一个粗略的圆圈,如下所示:
0x18: 00011000
0x24: 00100100
0x18: 00011000
由于8像素宽可创建相当小的图形(即使按Atari 2600标准),通常也可以将高度,宽度或两者都翻一番或翻两番,以创建同一图像的更大(虽然更块状和失真)的版本。对于玩家精灵和运动场,它们通常也会垂直或水平翻转。游戏《战斗》就是一个很好的例子。
挑战在于,编写代码以将这些精灵显示为ASCII形式的“图形”,包括能够垂直,水平或同时拉伸或翻转它们的能力。它必须采用完整程序或可调用函数的形式。
输入:
- 字节数组,每个字节代表该行的水平位。
- 水平和垂直每个方向的非零整数值,代表该尺寸的比例因子。
- 负值表示尺寸也应沿其轴翻转。
输出:
- ASCII表示为STDOUT或换行符分隔的字符串,对于黑色(0)像素使用空格字符,对于白色(1)像素使用您选择的任何可打印的非空格字符。
测试数据:
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]
注意:上面的示例输入字节数组以十六进制形式提供。如果您的平台不接受十六进制文字作为字节表示形式,则可以将其转换为与本地字节等效的文字。
示例输出:
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
--------------------------------
注意:上方和下方的水平线表示输出的开始和结束。在输出中不需要它们,但是如图所示,在开始和/或结束处都需要空行(由所有零/空格表示)。
注意2:这些测试位图的灵感来自维基百科上标记为“合理使用”的游戏屏幕截图,并根据它们进行了重新绘制/编码。