Page 1 of 2

New "colour" for drawPxel

PostPosted: Mon Aug 25, 2014 5:40 pm
by Matrix828
How about, in addition to BLACK and WHITE colours we have an INVERT option?
Eg,
Code: Select all
gb.display.color = INVERT;
gb.display.drawPixel(x, y);


And obviously, if the pixel at (x, y) is white, then it will be set to black, and vise-versa.

Re: New "colour" for drawPxel

PostPosted: Wed Aug 27, 2014 10:06 am
by rodot
Mmh why not, that could be interesting and wouldn't take a lot more coding at first glance.

Re: New "colour" for drawPxel

PostPosted: Wed Aug 27, 2014 9:39 pm
by DFX2KX
yeah, that seems useful. It'll be a teeny bit slower because of having to check pixels, but it wouldn't be that bad in the scheme of things.

Re: New "colour" for drawPxel

PostPosted: Wed Sep 03, 2014 12:41 pm
by yodasvideoarcade
That would definetely be useful, especially when drawing bitmaps. You would easily recognize overlapping images since they come out inverted.

Basically it's just adding the bits together, no checking of pixels neccesary.

Re: New "colour" for drawPxel

PostPosted: Thu Sep 04, 2014 6:28 am
by rodot
yodasvideoarcade wrote:Basically it's just adding the bits together, no checking of pixels neccesary.

You'll have to read the current color of the pixel in the display buffer in order to be able to invert it.

Re: New "colour" for drawPxel

PostPosted: Sun Sep 07, 2014 10:40 am
by rodot
I added the INVERT color in the last commit to the beta branch ;)

Re: New "colour" for drawPxel

PostPosted: Fri Sep 12, 2014 7:54 pm
by TheTurnipKing
Shouldn't you just be able to use a logical operation? The current value doesn't matter. Adding 1 should flip it from 1 to 0 OR 0 to 1.

Re: New "colour" for drawPxel

PostPosted: Fri Sep 12, 2014 8:13 pm
by rodot
Of course the current value matters, how to you want to invert a pixel if you don't know its initial value :)
Yes it "just use a logical operation" as it's set the pixel to the opposite of its current value.
You can't just add 1 to a pixel because pixels are stored 8 by 8 in bytes (a byte contains 8 bits), and there is no bitwise addition.

But anyway now it's in the library and working, enjoy :)

Re: New "colour" for drawPxel

PostPosted: Sat Sep 13, 2014 6:42 am
by TheTurnipKing
The initial value shouldn't matter if the content of the bit is just going to be flipped, especially if you can flip the bit either way with the same operation.

I'm pretty sure Arduino has bitwise operators, but I'm not yet familar with how the Gamebuino library is mapping the screen in memory.

Rightly enough, It probably is more hassle than it's worth on a 16mhz microcontroller though. I just remember a lot of this stuff from my 3.5mhz home micro days.

Re: New "colour" for drawPxel

PostPosted: Sat Sep 13, 2014 9:20 am
by rodot
Well why not but how do you flip a single bit in a byte then ?