User blog:SlackerPrime/Code Dump: Writing to a palette color using RGB

(first blog post whee)

I've recently been working on tech demos that involve palette modification. It's basically been my obsession. In these cases I've found it easier to just convert the color into RGB and then back again because it's easier to do math on base-10 numbers than hex numbers. COLREAD does this for you: it returns the R, G, and B variables as standard RGB integers, instead of hex. However, COLSET forces you to convert those values into a hex string.

Why? Who knows? It just makes life harder.

So I got to work. It turns out, you can just use HEX$ to convert your RGB values, and then you add them into a string in that order.

Here's the code, folks: 'A bright red-purple, set to GRP color 1 R=255 B=127 G=0 R$=HEX(R) G$=HEX(G) B$=HEX(B) IF LEN(R$)<2 THEN R$="0"+R$ IF LEN(G$)<2 THEN G$="0"+G$ IF LEN(B$)<2 THEN B$="0"+B$ C$=R$+G$+B$ COLSET "GRP",1,C$