1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,math; const C_W=500; C_H=500;
type TKomplex = record Re, Im: Double; end;
TForm1 = class(TForm) Button1: TButton; Image1: TImage; procedure Button1Click(Sender: TObject); procedure Image1Click(Sender: TObject); private public pfad: array[1..20000] of TKomplex; ctr: array[0..C_W, 0..C_H] of Single;
end; var Form1: TForm1; cando:Boolean; implementation
{$R *.dfm}
function Komplex(a, b: Single): TKomplex; begin Result.Re := a; Result.Im := b; end;
function ComplexAbs(x: TKomplex): Double; begin Result := Sqrt(x.Im * x.Im + x.Re * x.Re); end;
function ComplexAdd(a, b: TKomplex): TKomplex; begin Result.Re := a.Re + b.Re; Result.Im := a.Im + b.Im; end;
function ComplexSqr(x: TKomplex): TKomplex; begin Result.Re := x.Re * x.Re - x.Im * x.Im; Result.Im := 2 * x.Re * x.Im; end;
procedure TForm1.Button1Click(Sender: TObject); CONST PixelCountMax = MaxInt / 3; TYPE pRGBTripleArray = ^TRGBTripleArray; TRGBTripleArray = ARRAY[0..$effffff] OF TRGBTriple; var pscanLine : pRGBTripleArray; x, y, xx, yy, i, j: Integer; c, z, zz: TKomplex; a, w, h: Single; maxctr: Single; bmp:TBitMap; WH,HH:Integer; begin Image1.Width := C_W; Image1.Height := C_H; WH := C_W div 2; HH := C_H div 2; bmp:=TBitMap.Create; try bmp.PixelFormat := pf24bit; bmp.Width := C_W; bmp.Height := C_H;
for x := 0 to C_W - 1 do for y := 0 to C_H - 1 do ctr[x, y] := 0; maxctr := 0; for i := LOW(pfad) to High(pfad) do pfad[i] := Komplex(0, 0); w := 1.5; h := 1.5;
for x := 0 to C_W - 1 do for y := 0 to C_W - 1 do begin z := Komplex(0, 0); c := Komplex((x - WH) * w / WH, -(y - HH) * h / HH); i := 0; a := ComplexAbs(z); while (a <= 2) and (i < High(pfad)) do begin zz := ComplexSqr(z); z := ComplexAdd(zz, c); Inc(i); pfad[i] := z; a := ComplexAbs(z); end;
if (a > 2) then begin for j := 1 to i do begin if not ( (pfad[j].Re = 0) and (pfad[j].Im = 0)) then begin xx := Round(WH + pfad[j].Re * WH / w); yy := Round(HH - pfad[j].Im * (HH) / h);
if (xx > -1) and (xx < (C_W - 1)) and (yy > -1) and (yy < (C_H - 1)) then begin ctr[xx, yy] := ctr[xx, yy] + 1; if (ctr[xx, yy] > maxctr) then maxctr := ctr[xx, yy]; end; end; end; end; end; if maxctr > 0 then maxctr := LnXP1(maxctr ); for y := 0 to C_H - 1 do begin pscanLine := bmp.Scanline[y]; for x := 0 to C_W -1 do begin
if ctr[x, y] >= 1 then ctr[x, y] := LnXP1(ctr[x, y] ); pscanLine[x].rgbtBlue := Trunc(255 * ctr[x, y] / maxctr ); pscanLine[x].rgbtRed := 0; pscanLine[x].rgbtGreen := 0; end; end; image1.Picture.bitmap.Assign(bmp); finally bmp.Free; end;
end;
Procedure InvertBitMap24(bmp:TBitMap); CONST PixelCountMax = MaxInt / 3; TYPE pRGBTripleArray = ^TRGBTripleArray; TRGBTripleArray = ARRAY[0..$effffff] OF TRGBTriple; var pscanLine : pRGBTripleArray; x,y:Integer; begin for Y := 0 to bmp.Height -1 do begin pscanLine := bmp.Scanline[y]; for x := 0 to bmp.Width -1 do begin pscanLine[x].rgbtBlue := pscanLine[x].rgbtBlue XOR 255; pscanLine[x].rgbtGreen := pscanLine[x].rgbtGreen XOR 255; pscanLine[x].rgbtRed := pscanLine[x].rgbtRed XOR 255; end; end; end;
Procedure InvertBitMap32(bmp:TBitMap); CONST PixelCountMax = MaxInt / 3; TYPE pRGBQuadArray = ^TRGBQuadArray; TRGBQuadArray = ARRAY[0..$effffff] OF TRGBQuad; var pscanLine : pRGBQuadArray; x,y:Integer; begin for Y := 0 to bmp.Height -1 do begin pscanLine := bmp.Scanline[y]; for x := 0 to bmp.Width -1 do begin pscanLine[x].rgbBlue := pscanLine[x].rgbBlue XOR 255; pscanLine[x].rgbGreen := pscanLine[x].rgbGreen XOR 255; pscanLine[x].rgbRed := pscanLine[x].rgbRed XOR 255; end; end; end;
Procedure InvertBitMap(bmp:TBitMap); begin if bmp.PixelFormat=pf32Bit then InvertBitMap32(bmp) else if bmp.PixelFormat=pf24Bit then InvertBitMap24(bmp); end;
procedure MirrorBitmap(Bmp, MBmp: TBitmap;Horizonal:Boolean=true); var x1, x2, y1, y2: integer; begin MBmp.Width := Bmp.Width; MBmp.Height := Bmp.Height; if Horizonal then begin x1 := MBmp.Width - 1; x2 := - 1; y1 := 0; y2 := MBmp.Height; end else begin x1 := 0; x2 := MBmp.Width; y1 := MBmp.Height - 1; y2 := -1; end; MBmp.Canvas.CopyRect(Rect(x1, y1, x2, y2), Bmp.Canvas, Rect(0, 0, MBmp.Width, MBmp.Height)); end; procedure TForm1.Image1Click(Sender: TObject); begin InvertBitMap(Image1.Picture.Bitmap); Image1.Invalidate; end;
end. |