Hi!
TLDR:
Color tables are basically free to use because the gfx pipeline uses one by default. By modifying it we can achieve effects-in this case we add 2 colors that allow us to draw "shadows" and add lit areas. Copy the function below and give it a 64x64 sprite as a color table. Now draw shapes with color 32 and 33 to apply the effects.
My attempt at explaining color tables
I've struggled with understanding color tables, but thanks to @washburnello I finally got it. He is using a sprite to visually represent the color table, which makes it much easier to plan.
This small function allows you to do the same and use a 64x64 sprite to visually represent and plan the color table. It then memmaps it into the appropriate spot in memory.
The color table sprite looks like this:
On the vertical axis are the colors that you are drawing with. The horizontal axis are the colors that are already on screen at whatever position you're drawing. Their intersection is the color that will get drawn instead.
The first 32 colors will always get drawn as themselves(in this case) with the exception of color 0, which is always mapped to the color that is already on screen. This is how Picotron makes transparency work.
Two colors got added: Color 32 and 33 have alterations to achieve the lightning effects. Color 34 is another set of our original colors as a starting point for your own custom effect color.
This is the function:
function apply_color_table(color_table_sprite) local sprite=get_spr(color_table_sprite) --copy the sprite into the address 0x8000 in memory memmap(sprite,0x8000) --poke the bit that makes it work for shapes(circ,rect etc.), the bit for sprites --is already set by default. poke(0x550b,0x3f) --the color table got copied and will be used. This is the same color table --that pal() modifies. end |
The function takes the sprite, which is userdata, and puts it in the appropriate spot in memory. It also does a poke poke(0x550b, 0x3f)
to make the gfx pipeline apply the color table to shapes like rectfill
etc.
The cart provided above will result in this effect:

Picotron has the ability to handle 64 colors, but only 32 are being used by default. The color table allows us to define color 32 and 33 as our "shadow" or "light" color respectively. Play around with the color table, switch colors around, add more shapes to the code, make them overlap, have fun!
I enjoyed playing around with it a lot and came up with a little sample scene. All the lightning effects were achieved using nothing but shapes drawn with color 33 and 32.




It's worth highlighting that in order for colour tables to work with shapes, you must
poke(0x550b, 0x3f)
.


.jpg)
The function does exactly that, but I will also add the poke to the description in this post, for now I had just mentioned it.
[Please log in to post a comment]