From: "Mark Q" Newsgroups: borland.public.delphi.graphics Subject: Interesting effect with XOR Date: Sun, 18 Nov 2001 23:36:35 +1100 Lines: 49 X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 NNTP-Posting-Host: 203.134.32.176 Message-ID: <3bf7ac1e$1_2@dnews> X-Trace: dnews 1006087198 203.134.32.176 (18 Nov 2001 04:39:58 -0800) Path: dnews Xref: dnews borland.public.delphi.graphics:43674 Hello, I just thought some of you might find this "special effect" vaguely interesting. It reminds me of a fractal I once saw. Create a new application, add a button to the form, and add the following code for the button's onclock event: var bih : TBitmapInfo; i, j : Byte; ptrBits, ptrTemp : Pointer; begin // Initialise BITMAPINFO structure ZeroMemory(@bih, SizeOf(bih)); with bih.bmiHeader do begin biSize := SizeOf(TBitmapInfoHeader); biWidth := 256; biHeight := 256; biPlanes := 1; biBitCount := 24; biSizeImage := 256*256*3; end; {with} // Allocate memory for pixel data ptrBits := GlobalAllocPtr(GMEM_FIXED or GMEM_ZEROINIT, 256*256*3); try ptrTemp := ptrBits; // Manipulate pixels using XOR operator for j := 0 to 255 do begin for i := 0 to 255 do begin PByte(ptrTemp)^ := i xor j; // Blue component Inc(PByte(ptrTemp)); PByte(ptrTemp)^ := i xor j; // Green component Inc(PByte(ptrTemp)); PByte(ptrTemp)^ := i xor j; // Red component Inc(PByte(ptrTemp)); end; {for} end; {for} // Draw to screen StretchDIBits(Canvas.Handle, 0, 255, 256, -256, 0, 0, 256, 256, ptrBits, bih, DIB_RGB_COLORS, SRCCOPY); finally GlobalFreePtr(ptrBits); end; {try} end; // tested for Delphi 4 // Mark Q