Pico-8 Bach Inventions Effects ~ Day 8: Magical Drink (Patreon)
Content
Hi everyone!
Today's portrait features a suspiciously colorful drink and while Bach wonders whether or not he should drink it, we're going to look at how it works!
Let's start by looking at the sprite-sheet!
As you can see, the 'liquid' part of the sprite is all green. After drawing that sprite on the screen, all we have to do is find those green pixels and replace them with the rainbow color defined by 'flr((x*0.5+y)/8+t*4)%7+8'.
To find those pixels, we'll use 'pget(x,y)' on every pixel of the rectangle occupied by those green pixels like so:
<code>for y=84,108 do
for x=91,108 do
if pget(x,y)==11 then
local c=flr((x*0.5+y)/8+t*4)%7+8
pset(x,y,c)
end
end
end
</code>
To get those coordinate boundaries, I simply made a guess, ran the program, tweaked the values, ran again, tweaked again, until I have exactly the right coordinates. Alternatively you could have calculated them from the position where you drew the sprite, it would have been cleaner but this took me less than 2 minutes so why would I make it any more complicated?
But if you look closely at the sprite-sheet, you might see some dark-green pixels at the bottom of the drink. We'll scan for those too and when we find them, we'll use the darker shade of the rainbow color, using this array: drk={[0]=0,0,1,1,2,1,13,6,2,4,9,3,1,1,2,4}
That's our rainbow drink figured out. Let's make it fizzy!
I won't have to write much on this since I'm using something very similar to the dust/snow effect we saw last week, only this time the particles only go up, they're always just one pixel, you draw them only if the underlying pixel is green, and the particle can appear either white or dark-green! This must happen before the rainbow treatment, so that the rainbow treatment picks up the dark-green particles.
And that's it, our fizzy magical cocktail is done! Do ask any questions you might have!
As usual, the downloads for this portrait are available to my 5$+ supporters over there!
Thank you for reading!
Take care!
TRASEVOL_DOG