Change color values of an Int color?

Miscellaneous Forums/General Discussion/Change color values of an Int color?

Say I have a color $FF804020, I it's 'alpha,red,green,blue' right?

How can I change just 1 color of the value, say, replace FF with 30 to make it $30804020?

TIA!

I'd convert it first - calculate it - then convert it back.

Well to get back to Component Colors, it's

alpha = (argb shr 24) and 255
red = (argb shr 16) and 255
green = (argb shr 8) and 255
blue = (argb and 255)


Then to get them back to an int

argb = (alpha shl 24) or (red shl 16) or (green shl 8) or (blue)


So I guess you would grab the green, blue and alpha, and make a new argb int with those and your new red value.

EDIT: And, of course, if it's BlitzMax, it's & and | rather than "And" and "Or" but I'm sure you already knew that.

puki: come to IRC, I'd like to introduce you to a large trout.

Gabriel: Cheers, that'll do nicely.

I'm not sure why it was so hard to work that out though. I mean a blind slug, wearing mittens, and having only half a brain could work that one out.

Ask us something harder next time.

Well put your mittens on, and give us a 1 line solution :)

A one line solution might be technically slower.

I'm not sure why it was so hard to work that out though. I mean a blind slug, wearing mittens, and having only half a brain could work that one out
Bit strong, but have to agree
Colour:& ($ff00ffff + 30 shl 16)
A one line solution to change the red component to 30

I don't use Bmax.

I'm hard-core.

Wait a minute!

This 'Shl' thing is in Blitz3D!

I've never, ever noticed it before.

I bet "Scouse" feels a bit of a 'tard now.

Adding works, but Or is better. :)

You shouldn't be using `and` and `or` you should be using & and |

You shouldn't be using `and` and `or` you should be using & and |

Not if you're using B3D or B+ you shouldn't. I already covered this.