Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
11-19-2022, 04:08 AM
(This post was last modified: 11-19-2022, 04:27 AM by CharlieJV.)
I was studying "Bitwise NOT", and just had this thought about what impact that would have on color when applied to each of the RGB values.
Is there any related "color theory" that discusses anything similar to this sample code I just wrote?
Code: (Select All) screen _newimage(600,400,32)
dim as _unsigned _byte r,g,b,r2,g2,b2
again:
r = int(rnd*256)
g = int(rnd*256)
b = int(rnd*256)
r2 = not r
g2 = not g
b2 = not b
line (0, 0)-(200, 200),_rgb32(r,g,b),BF
line (300, 0)-(500, 200),_rgb32(r2,g2,b2),BF
_delay 0.5
goto again
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
If you use "PUT" graphics statement with XOR mode. So the image could always be seen, although weird sometimes.
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
(11-19-2022, 04:23 AM)mnrvovrfc Wrote: If you use "PUT" graphics statement with XOR mode. So the image could always be seen, although weird sometimes.
You've lost me.
Are you saying the XOR in PUT does the same thing as what these Bitwise NOT's are doing in my sample code?
If so, I think I'm going to need some help understanding how that can be.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
Note: the array might be too big. I tried to use a string as was suggested in the Wiki but failed, increased it as much as 16 million. :O
The first time "XOR" is used, it's on black so it's just the same as "PSET".
The other time, a totally-white opaque block is drawn before the buffer overlays it, getting the same results as your rectangle.
Code: (Select All) screen _newimage(600,400,32)
dim as _unsigned _byte r,g,b,r2,g2,b2
dim blk(1 to 400, 1 to 400) as long
again:
r = int(rnd*256)
g = int(rnd*256)
b = int(rnd*256)
r2 = not r
g2 = not g
b2 = not b
line (0, 0)-step(200, 200),_rgb32(r,g,b),BF
get (0, 0)-(199, 199), blk
line (300, 200)-step(200, 200),_rgb32(r2,g2,b2),BF
put (0, 200), blk, XOR
line(300, 0)-step(199, 199), _rgb32(255, 255, 255, 255), BF
put (300, 0), blk, XOR
end
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
In this case, your color values are simply 255 - value at the end of the day.
Code: (Select All) Dim NotI As _Unsigned _Byte
_Define C As _UNSIGNED LONG
For i = 0 To 255
c = _RGB32(i, i, i)
NotI = Not i
c1 = _RGB32(NotI, NotI, NotI)
c2 = _RGB32(255 - i, 255 - i, 255 - i)
Print i, NotI, c, c1, c2
Sleep
Next
Whatever r, g, b is for you, you're using NOT to change the 0 to 255 value of it...
NOT 0 becomes -1.
NOT 1 becomes -2.
NOT 2 becomes -3.
...and so on...
Which you then store in an _UNSIGNED BYTE:
-1 as an unsigned byte is 255.
-2 as an unsigned byte is 254.
-3 as an unsigned byte is 253.
...and so on...
Nothing at all wrong with what you're doing, but I think it'd be a little easier to read and understand if you just kept it simple with:
Code: (Select All) screen _newimage(600,400,32)
dim as _unsigned _byte r, g, b
again:
r = int(rnd*256)
g = int(rnd*256)
b = int(rnd*256)
line (0, 0) - (200, 200), _rgb32(r,g,b), BF
line (300, 0) - (500, 200), _rgb32(255 - r,255 - g, 255 -b), BF
_delay 0.5
goto again
Posts: 597
Threads: 110
Joined: Apr 2022
Reputation:
34
(11-19-2022, 04:42 AM)mnrvovrfc Wrote: Note: the array might be too big. I tried to use a string as was suggested in the Wiki but failed, increased it as much as 16 million. :O
The first time "XOR" is used, it's on black so it's just the same as "PSET".
The other time, a totally-white opaque block is drawn before the buffer overlays it, getting the same results as your rectangle.
Code: (Select All) screen _newimage(600,400,32)
dim as _unsigned _byte r,g,b,r2,g2,b2
dim blk(1 to 400, 1 to 400) as long
again:
r = int(rnd*256)
g = int(rnd*256)
b = int(rnd*256)
r2 = not r
g2 = not g
b2 = not b
line (0, 0)-step(200, 200),_rgb32(r,g,b),BF
get (0, 0)-(199, 199), blk
line (300, 200)-step(200, 200),_rgb32(r2,g2,b2),BF
put (0, 200), blk, XOR
line(300, 0)-step(199, 199), _rgb32(255, 255, 255, 255), BF
put (300, 0), blk, XOR
end
Just tried it, and I see what is going on.
The RGB components of a color, NOT-TING each of them results in a color.
Taking that original color, if we XOR it with white, we get the same color as the NOT-TING.
So what's the resulting color? Is it an opposite color? A something-something color?
I'd like to know what we call what is going on, to go read the related color therory.
|