When giving Kirby's Dream Land 2 the GBC treatment, I really wanted it to stand out. This was one of the most anticipated games to get the treatment, and I wanted to do as much as I could to make use of the expanded color hardware. As part of this, and also for adding extra support to the game's existing "rainbow" motif, I decided to give some sprite objects an animated rainbow effect.
This rainbow effect consists of a smooth transition from each 42ndth of the color wheel. Each frame, a lookup table of rainbow RGB values is referenced, and the loaded RGB values are thrown into the desired slot of the main palette buffer1. Therefore, only one palette slot for each brightness level of the rainbow effect is needed to display the effect, as 8 slots of 4/3 usable colors for BG/OBJ respectively is quite tight.
Obviously, generating these values during execution is a bit much for our 8-bit pal, so they're pre-written in ROM. This was the Super Cool And Fun Woohoo Party Time part--actually generating a smooth effect. My first attempts at this were quite janky, with the color animation appearing in quick dashes and being rather tough to look at. It took me quite a while to solve this issue.
Luckily though, I stumbled upon an existing algorithm that did the trick. I rewrote this code in Python and got my desired smooth rainbows.
the code i did
```
import math
#
def rgb(r, g, b):
outstring = "\tRGB "
outstring += str(r // 16 + 16) + ", " + str(g // 16 + 16) + ", " + str(b // 16 + 16) + ", "
outstring += str(r // 8) + ", " + str(g // 8) + ", " + str(b // 8) + ", "
outstring += str(r // 16) + ", " + str(g // 16) + ", " + str(b // 16) + ", "
print(outstring)
#
def printColors(numColors):
#Adapted from http://www.markandey.com/2012/04/how-to-generate-rainbow-colors.html
freq = 6 / numColors
for i in range(numColors):
r = math.floor(math.sin(freq * i + 0) * (127) + 128)
g = math.floor(math.sin(freq * i + 1) * (127) + 128)
b = math.floor(math.sin(freq * i + 3) * (127) + 128)
rgb(int(r), int(g), int(b))
#
printColors(42)
```
While there's not much else I have to say about how it works, this does remain one of the parts of the hack I'm most proud of pulling off. I have a soft-spot for demoscene-esque2 effects, and also really like Jazz Jackrabbit 1's smooth color animation, and I felt like I could add that extra flare to my most well-versed platform to develop for. This is also why there's a smooth low health blink effect on the health bar, which I fully added the toggle for since it felt it was just pure extra compared to the rainbow effect's theme-fittingness.
Additional fun fact: I initially had the idea just for the status bar item icon, but as soon as I first implemented it, I thought, "hey, I could make the rainbow sword like this!"
And just for comparison, the one example off the top of my head of this effect an in official GBC title, that being in LADX's inventory screen, albeit slower. There's probably more official examples scattered about that I'm not aware of/remembering right now, so do let me know if you're aware of any!
-
Fun fact: There are 55 different palette buffers--13 for BGs and OBJs each fading to/from white, 13 for BGs and OBJs each fading to/from black, 1 for BGs and OBJs each for the powerup dim effect, and 1 half-sized one for the status bar's mid-frame palette swap. The rainbow effect only writes to the first one, the unfaded to/from white one, i.e. the one mostly used. So it's just white during fades. Hey, this is an 8-bit toy doing multiple bitshifts to/from just for cooler fades.
-
Would comparing this hack to a demoscene production be a stretch? I mean, even if it did tickle some color-mode effects, it's still constrained to an existing program designed for the DMG/SGB specifically.