抱歉,这个问题有点深奥,但我还是想不起来!
我正在研究街机游戏DoDonPachi(以及许多其他较旧的游戏)中使用的淡入淡出算法:
我写了一个python脚本来挑选一些像素,并在淡入淡出的过程中跟踪它们。这是结果的代表性示例。每组的第一行是起始颜色值,而随后的每一行是当前帧的颜色值和前一帧的颜色值之间的差。
Starting Value: (132, 66, 189)
Frame 1: [9, 9, 8]
Frame 2: [8, 8, 8]
Frame 3: [8, 8, 8]
Frame 4: [8, 8, 9]
Frame 5: [9, 9, 8]
Frame 6: [8, 8, 8]
Frame 7: [8, 8, 8]
Frame 8: [8, 8, 9]
Frame 9: [9, 0, 8]
Frame 10: [8, 0, 8]
Frame 11: [8, 0, 8]
Frame 12: [8, 0, 9]
Frame 13: [9, 0, 8]
Frame 14: [8, 0, 8]
Frame 15: [8, 0, 8]
Frame 16: [8, 0, 9]
Frame 17: [0, 0, 8]
Frame 18: [0, 0, 8]
Frame 19: [0, 0, 8]
Frame 20: [0, 0, 9]
Frame 21: [0, 0, 8]
Frame 22: [0, 0, 8]
Frame 23: [0, 0, 8]
Frame 24: [0, 0, 0]
Frame 25: [0, 0, 0]
Frame 26: [0, 0, 0]
Frame 27: [0, 0, 0]
Frame 28: [0, 0, 0]
Frame 29: [0, 0, 0]
Starting Value: (132, 0, 0)
Frame 1: [9, 0, 0]
Frame 2: [8, 0, 0]
Frame 3: [8, 0, 0]
Frame 4: [8, 0, 0]
Frame 5: [9, 0, 0]
Frame 6: [8, 0, 0]
Frame 7: [8, 0, 0]
Frame 8: [8, 0, 0]
Frame 9: [9, 0, 0]
Frame 10: [8, 0, 0]
Frame 11: [8, 0, 0]
Frame 12: [8, 0, 0]
Frame 13: [9, 0, 0]
Frame 14: [8, 0, 0]
Frame 15: [8, 0, 0]
Frame 16: [8, 0, 0]
Frame 17: [0, 0, 0]
Frame 18: [0, 0, 0]
Frame 19: [0, 0, 0]
Frame 20: [0, 0, 0]
Frame 21: [0, 0, 0]
Frame 22: [0, 0, 0]
Frame 23: [0, 0, 0]
Frame 24: [0, 0, 0]
Frame 25: [0, 0, 0]
Frame 26: [0, 0, 0]
Frame 27: [0, 0, 0]
Frame 28: [0, 0, 0]
Frame 29: [0, 0, 0]
Starting Value: (165, 156, 222)
Frame 1: [9, 8, 8]
Frame 2: [8, 8, 8]
Frame 3: [8, 8, 8]
Frame 4: [8, 9, 9]
Frame 5: [9, 8, 8]
Frame 6: [8, 8, 8]
Frame 7: [8, 8, 8]
Frame 8: [8, 9, 9]
Frame 9: [9, 8, 8]
Frame 10: [8, 8, 8]
Frame 11: [8, 8, 8]
Frame 12: [8, 9, 9]
Frame 13: [9, 8, 8]
Frame 14: [8, 8, 8]
Frame 15: [8, 8, 8]
Frame 16: [8, 9, 9]
Frame 17: [9, 8, 8]
Frame 18: [8, 8, 8]
Frame 19: [8, 8, 8]
Frame 20: [8, 0, 9]
Frame 21: [0, 0, 8]
Frame 22: [0, 0, 8]
Frame 23: [0, 0, 8]
Frame 24: [0, 0, 9]
Frame 25: [0, 0, 8]
Frame 26: [0, 0, 8]
Frame 27: [0, 0, 8]
Frame 28: [0, 0, 0]
Frame 29: [0, 0, 0]
Starting Value: (156, 90, 206)
Frame 1: [8, 8, 8]
Frame 2: [8, 8, 9]
Frame 3: [8, 8, 8]
Frame 4: [9, 9, 8]
Frame 5: [8, 8, 8]
Frame 6: [8, 8, 9]
Frame 7: [8, 8, 8]
Frame 8: [9, 9, 8]
Frame 9: [8, 8, 8]
Frame 10: [8, 8, 9]
Frame 11: [8, 8, 8]
Frame 12: [9, 0, 8]
Frame 13: [8, 0, 8]
Frame 14: [8, 0, 9]
Frame 15: [8, 0, 8]
Frame 16: [9, 0, 8]
Frame 17: [8, 0, 8]
Frame 18: [8, 0, 9]
Frame 19: [8, 0, 8]
Frame 20: [0, 0, 8]
Frame 21: [0, 0, 8]
Frame 22: [0, 0, 9]
Frame 23: [0, 0, 8]
Frame 24: [0, 0, 8]
Frame 25: [0, 0, 8]
Frame 26: [0, 0, 0]
Frame 27: [0, 0, 0]
Frame 28: [0, 0, 0]
Frame 29: [0, 0, 0]
如您所见,从每个帧的每个颜色分量中减去8或9。此外,即使每个颜色分量的起始减去值都不相同,数字9也会始终出现在数字8之后的三帧。还要注意,每个颜色分量达到0(即黑色)的差为8或9,而不是任意的余数。这意味着8,8,8,9的减法值循环永不中断!(编写此算法可能是为了确保淡入淡出的最后一帧与其他帧一样平滑。)
现在,这使我感到困惑。根据我的计算,如果您逆转此过程-即以8、8、8、9周期进行相加,以找出29帧中的所有可能组合,则只会得到52个唯一数字。但是碰巧的是,每个颜色分量都是该集合的成员!这意味着要么专门为该渐变算法选择颜色(不太可能),要么渐变算法是围绕游戏的调色板设计的。但是到底有人会发现,如果您采用8,8,8,9,适当地改变周期,并不断从调色板中的每个颜色分量中减去数字,最终每种颜色将达到0? !我必须缺少一些数学技巧。它是什么?