Hello
You could also apply 2's-Compliment to the colour using bitwise NOT (..) and adding 1.
2's compliment steps
Flip all the bits
Add 1
*** edit ***
Also, colour variables should be assigned as a dword. tsk, tsk!
sync on
col as dword
col = rgb(255,0,255)
do
if timer()>time1+200
col=rgb(rnd(255),rnd(255),rnd(255))
time1=timer()
endif
ink col,0
box 10,10,110,110
ink -col-1,0
box 110,10,210,110
ink col xor rgb(255,255,255),0
box 210,10,310,110
ink InvCol(col),0
box 310,10,410,110
ink InvCol2(col), 0
box 250, 150, 350, 250
sync
loop
function invCol(col1)
Local col as dword
col=rgb(255-rgbr(col1),255-rgbg(col1),255-rgbb(col1))
endfunction col
function invCol2(col1)
`Applies 2's compliment to the colour using bitwise NOT (..)
`
` 2's compliment steps
` Flip all the bits
` Add 1
Local col as dword
col = (col1 .. col1) + 1
endfunction col
*** edit 2 ***
it just occured to me that by inverting the colour, the alpha byte was also inverted.
This function sorts that out.
Remstart
Applies 2's compliment to the colour using bitwise NOT (..)
and maintains the alpha byte value using bitwise OR (||)
2's compliment steps
Flip all the bits
Add 1
Maintaining the Alpha byte with a bitwise OR (||)
0xFF000000 is the alpha byte
If we OR it with num (num = 0x000000ff)
0x000000ff || 0xff000000 = 0xff0000ff
num's alpha byte can be any value
With an OR being applied, only one of the bits has to be on
for the OR result to be true
as we're ORing with alpha value 0xff000000
any bits represented by the ff return true
(num = 0x010000ff)
0x010000ff || 0xff000000 = 0xff0000ff
(num = 0x200000ff)
0x200000ff || 0xff000000 = 0xff0000ff
Remend
function invCol3(col1)
Local col as dword
col = ((col1 .. col1) + 1) || 0xFF000000
`Ink col, 0
`Text 0, 260, Hex$(col)
endfunction col