unit R24; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TRei24 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; const Yoko = 37; Tate = 27; DYoko = Yoko * 16; DTate = Tate * 16; TX = 312; //目标X 坐标, TY = 224; //目标Y 坐标, var Rei24: TRei24; BackBmap,MakeBmap : TBitmap; RectB,RectM,RectD : TRect; AT,Ct,LW :Byte; //AT 0,恢复制作图像,攻击方式,1,2,3,4 implementation {$R *.dfm} procedure TRei24.FormCreate(Sender: TObject); begin BackBmap := TBitmap.Create; BackBmap.Width := DYoko; BackBmap.Height := DTate; BackBmap.LoadFromFile(GetCurrentDir + '\Bunny.bmp'); MakeBmap := TBitmap.Create; MakeBmap.Width := DYoko + 32; MakeBmap.Height := DTate + 32; end; procedure TRei24.Timer1Timer(Sender: TObject); var Bt : Byte; begin case AT of 0: begin //恢复MAKEBMAP, MakeBmap.Canvas.CopyMode := cmSrcCopy; RectB := Rect(48,24,640,480 - 24); RectM := Rect(16,16,DYoko + 16,DTate + 16); MakeBmap.Canvas.CopyRect(RectM,BackBmap.Canvas,RectB); end; 1: begin MakeBmap.Canvas.Pen.Mode := pmXor; MakeBmap.Canvas.Pen.Width := 1; MakeBmap.Canvas.Pen.Color := clYellow; MakeBmap.Canvas.Brush.Color := clOlive; Bt := Ct; //Ct计数, MakeBmap.Canvas.Ellipse(TX - Bt * 8,TY - 20 - Bt * 8, TX + Bt * 8,TY + 20 + Bt * 8); if Ct >= 33 then //大于33 画2圈,结果就或回去了恢复原图像? begin Bt := Ct - 32; MakeBmap.Canvas.Ellipse(TX - Bt * 8,TY - 20 - Bt * 8, TX + Bt * 8,TY + 20 + Bt * 8); end; Ct := Ct + 1; if Ct > 80 then //计次到80 AT := 0; end; 2: begin MakeBmap.Canvas.Pen.Mode := pmXor; MakeBmap.Canvas.Pen.Width := 2; MakeBmap.Canvas.Pen.Color := clWhite; MakeBmap.Canvas.Brush.Color := clBlack; if Ct = 0 then //初始画25个圈 for Bt := 25 downto 1 do MakeBmap.Canvas.Ellipse(TX - Bt * 8,TY - Bt * 8, TX + Bt * 8,TY + Bt * 8) else begin Bt := 26 - Ct; //开始xor 掉这25个圈 MakeBmap.Canvas.Ellipse(TX - Bt * 8,TY - Bt * 8, TX + Bt * 8,TY + Bt * 8); end; Ct := Ct + 1; if Ct > 26 then //计次判断,结束 AT := 0; end; 3: begin MakeBmap.Canvas.Pen.Mode := pmXor; MakeBmap.Canvas.Pen.Width := 3; MakeBmap.Canvas.Pen.Color := clGreen; MakeBmap.Canvas.Brush.Color := clLime; MakeBmap.Canvas.Ellipse(TX - 150,TY - 170, TX + 150,TY + 170); Ct := Ct + 1; if Ct = 20 then AT := 0; end; 4: begin MakeBmap.Canvas.Pen.Mode := pmXor; case Ct and 3 of //PEN设置 0,1: begin LW := 38; MakeBmap.Canvas.Pen.Width := 25; MakeBmap.Canvas.Pen.Color := clRed; MakeBmap.Canvas.Brush.Color := clFuchsia; end; 2,3: begin LW := 48; MakeBmap.Canvas.Pen.Width := 30; MakeBmap.Canvas.Pen.Color := clPurple; MakeBmap.Canvas.Brush.Color := clWhite; end; end; //多边形 MakeBmap.Canvas.Polygon([ Point(TX - 4 * LW ,TY),Point(TX - 2 * LW,TY + LW), Point(TX - 3 * LW,TY + 3 * LW),Point(TX - LW,TY + 2 * LW), Point(TX,TY + 4 * LW),Point(TX + LW,TY + 2 * LW), Point(TX + 3 * LW,TY + 3 * LW),Point(TX + 2 * LW,TY + LW), Point(TX + 4 * LW,TY),Point(TX + 2 * LW,TY - LW), Point(TX + 3 * LW,TY - 3 * LW),Point(TX + LW,TY - 2 * LW), Point(TX,TY - 4 * LW),Point(TX - LW,TY - 2 * LW), Point(TX - 3 * LW,TY - 3 * LW),Point(TX - 2 * LW,TY - LW)]); Ct := Ct + 1; if ct = 23 then AT := 0; end; end; Rei24.Canvas.CopyMode := cmSrcCopy; RectM := Rect(16,16,DYoko + 16,DTate + 16); RectD := Rect(0,0,DYoko,DTate); Rei24.Canvas.CopyRect(RectD,MakeBmap.Canvas,RectM); end; procedure TRei24.Button1Click(Sender: TObject); begin if AT = 0 then begin AT := 1; Ct := 0; end; end; procedure TRei24.Button2Click(Sender: TObject); begin if AT = 0 then begin AT := 2; Ct := 0; end; end; procedure TRei24.Button3Click(Sender: TObject); begin if AT = 0 then begin AT := 3; Ct := 0; end; end; procedure TRei24.Button4Click(Sender: TObject); begin if AT = 0 then begin AT := 4; Ct := 0; end; end; procedure TRei24.FormClose(Sender: TObject; var Action: TCloseAction); begin BackBmap.Free; MakeBmap.Free; end; end.
这个程序比较简单,结构和前程序一样
在timer中进行计算,绘制
要点是XOR 异或后图像会恢复原色。
画圆 ellips
多边形 polygon
标签:24,MakeBmap,xor,TX,TY,Delphi,Canvas,LW,end From: https://www.cnblogs.com/D7mir/p/16618085.html