|
Author |
Topic: XOR drawing (Read 432 times) |
|
SJL
|
XOR drawing
« on: Jun 7th, 2004, 12:06pm » |
|
Hi there gurus, I am trying to draw something (lines, etc) using a XOR mode between the current strike color and the background. So far, I could not find in the documentation any fuction/method to specify the drawing mode (xor, and, or, etc). Do I have to dig to the java's Graphics2D handle in the applet or is there some easier way that I don't know about? Thanks! SJL
|
|
|
|
JohnG
|
Re: XOR drawing
« Reply #1 on: Jun 7th, 2004, 2:36pm » |
|
I don't think there's a default mode you can just switch on to do it. If you're willing to work out the pixels coloured with line yourself, you could use this: Code: color MyColour=new color(128,255,63); pixels[x+y*width]^=MyColour; |
| Or you could draw your line to a new BGraphics image, then do bitwise XOR into the displayed one: Code: BGraphics temp=new BGraphics(width,height); temp.background(0); temp.stroke(255,128,0); temp.line(0,0,30,30); for(int y=0;y<height;y++) { for(int x=0;x<width;x++) { pixels[x+y*width]^=temp.pixels[x+y*width]; } } |
| Here's an example I just cobbled together using the BGraphics method: http://www.hardcorepawn.com/XOR_stroke
|
« Last Edit: Jun 7th, 2004, 2:54pm by JohnG » |
|
|
|
|
SJL
|
Re: XOR drawing
« Reply #2 on: Jun 7th, 2004, 3:16pm » |
|
Excellent example applet. It does exactly what I had in mind. In fact, I want to draw a one pixel size rectagular frame using the mouse, and then zoom the content to the whole applet area on mouseRelease(). So I thought of XOR-ing the content with the stroke color such as to be able to restore the old content of the canvas when the mouse move. My problem was that not for a single second did I considered to directly access the pixels, well... Thank you! SJL.
|
|
|
|
|