Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ExtCtrls, StdCtrls;
- type TRGB = record
- b, g, r: byte;
- end;
- ARGB = array[0..0] of TRGB;
- PARGB = ^ARGB;
- type
- TForm1 = class(TForm)
- Image1: TImage;
- GroupBox1: TGroupBox;
- Memo1: TMemo;
- Button1: TButton;
- procedure Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- procedure Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- end;
- var
- Form1: TForm1;
- figure_state: array [0..3] of boolean=(false,false,false,false);
- coords: array [0..5] of integer=(200,100,50,100,100,50);
- points: array [0..3] of integer;
- implementation
- {$R *.dfm}
- const block=10;
- //------------------------------------------------------------------------------
- function gipotenus(x,y,z:word):word;
- begin
- if z=1 then result:=round(sqrt(sqr(x-coords[0])+sqr(y-coords[1])))
- else result:=round(sqrt(sqr(x-coords[3])+sqr(y-coords[4])));
- if result=0 then result:=1;
- end;
- //------------------------------------------------------------------------------
- function check_tochka_circle(x,y:word):boolean;
- begin
- if gipotenus(x,y,1)>coords[2] then result:=false
- else result:=true;
- end;
- //------------------------------------------------------------------------------
- function check_tochka_kardioda(x,y:word):boolean;
- begin
- if gipotenus(x,y,2)>coords[5]*(0.5+(x-coords[3]) / gipotenus(x,y,2)) then result:=false
- else result:=true;
- end;
- //------------------------------------------------------------------------------
- procedure draw_circle(x,y,r:word);
- Var i:integer;
- begin
- with Form1.Image1.Canvas do
- begin
- MoveTo(x+r,y);
- for i:=0 to 360 do
- begin
- LineTo(round(r*cos(i*pi/180))+x,round(r*sin(i*pi/180))+y);
- MoveTo(round(r*cos(i*pi/180))+x,round(r*sin(i*pi/180))+y);
- end;
- brush.Color:=clActiveCaption;
- Rectangle(x-r-block,y-r,x-r,y-r+block);
- brush.Color:=clBlack;
- Rectangle(x+r+block,y+r,x+r,y+r+block);
- end;
- coords[0]:=x;
- coords[1]:=y;
- coords[2]:=r;
- end;
- //------------------------------------------------------------------------------
- procedure draw_kardioida(x,y,r:word);
- Var i:integer;
- begin
- with Form1.Image1.Canvas do
- begin
- MoveTo(x+r,y);
- for i:=0 to 360 do
- begin
- if i=0 then MoveTo(round(r*(cos(i*pi/180)*(0.5+cos(i*pi/180))))+x,
- round(r*(sin(i*pi/180)*(0.5+cos(i*pi/180))))+y);
- LineTo(round(r*(cos(i*pi/180)*(0.5+cos(i*pi/180))))+x,
- round(r*(sin(i*pi/180)*(0.5+cos(i*pi/180))))+y);
- end;
- Brush.Color:=clyellow;
- Rectangle(x-block-r div 2,y-r-r div 2,x-r div 2,y-r+block-r div 2);
- brush.Color:=clBlack;
- Rectangle(x+2*r+block,y+r+r div 2-block,x+2*r,y+r+r div 2);
- end;
- coords[3]:=x;
- coords[4]:=y;
- coords[5]:=r;
- end;
- //------------------------------------------------------------------------------
- procedure draw_figures;
- Var i,j:integer;
- p: PARGB;
- square:integer;
- begin
- square:=0;
- Form1.Image1.Canvas.Pixels[0,0]:=clwhite;
- Form1.Image1.Picture.Bitmap.PixelFormat:=pf24bit;
- for j:=0 to Form1.Image1.Picture.Bitmap.Height -1 do
- begin
- p := Form1.Image1.Picture.Bitmap.Scanline[j];
- for i:=0 to Form1.Image1.Picture.Bitmap.Width -1 do
- begin
- begin
- p[i].r:=255;
- p[i].g:=255;
- p[i].b:=255;
- end;
- end;
- end;
- for j:=0 to Form1.Image1.Picture.Bitmap.Height -1 do
- begin
- p := Form1.Image1.Picture.Bitmap.Scanline[j];
- for i:=0 to Form1.Image1.Picture.Bitmap.Width -1 do
- begin
- if (check_tochka_circle(i,j) = true) and ( check_tochka_kardioda(i,j)=true) then
- begin
- inc(square);
- p[i].r:=255;
- p[i].g:=205;
- p[i].b:=205;
- end;
- end;
- end;
- draw_circle(coords[0],coords[1],coords[2]);
- draw_kardioida(coords[3],coords[4],coords[5]);
- Form1.Memo1.Lines.Clear;
- Form1.Memo1.Lines.Add('Площадь пересечения: '+IntToStr(square)+'px');
- Form1.Memo1.Lines.Add('X центра круга: '+IntToStr(coords[0]));
- Form1.Memo1.Lines.Add('Y центра круга: '+IntToStr(coords[1]));
- Form1.Memo1.Lines.Add('Радиус круга: '+IntToStr(coords[2]));
- Form1.Memo1.Lines.Add('X центра кардиоиды: '+IntToStr(coords[3]));
- Form1.Memo1.Lines.Add('Y центра кардиоиды: '+IntToStr(coords[4]));
- Form1.Memo1.Lines.Add('Радиус кардиоиды: '+IntToStr(coords[5]));
- end;
- //------------------------------------------------------------------
- procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- if (x<=(coords[0]-coords[2])) and (x>=(coords[0]-coords[2]-block)) and (y<=(coords[1]-coords[2]+block)) and (y>=(coords[1]-coords[2]))
- then
- begin
- figure_state[0]:=true;
- figure_state[1]:=false;
- figure_state[2]:=true;
- figure_state[3]:=false;
- end;
- if (x<=(coords[3]-coords[5] div 2)) and (x>=(coords[3]-coords[5] div 2-block)) and (y<=(coords[4]-coords[5]+block-coords[5] div 2)) and (y>=(coords[4]-coords[5]-coords[5] div 2))
- then
- begin
- figure_state[0]:=false;
- figure_state[1]:=true;
- figure_state[2]:=true;
- figure_state[3]:=false;
- end;
- if (x>=(coords[0]+coords[2])) and (x<=(coords[0]+coords[2]+block)) and (y<=(coords[1]+coords[2]+block)) and (y>=(coords[1]+coords[2]))
- then
- begin
- figure_state[0]:=true;
- figure_state[1]:=false;
- figure_state[2]:=false;
- figure_state[3]:=true;
- end;
- if (x>=(coords[3]+2*coords[5])) and (x<=(coords[3]+2*coords[5]+block)) and (y<=(coords[4]+coords[5]+coords[5] div 2)) and (y>=(coords[4]+coords[5]-block+coords[5] div 2))
- then
- begin
- figure_state[0]:=false;
- figure_state[1]:=true;
- figure_state[2]:=false;
- figure_state[3]:=true;
- end;
- end;
- //------------------------------------------------------------------
- procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- begin
- if (figure_state[3]=true) and (figure_state[0]=true) then
- begin
- coords[2]:=round(sqrt(sqr(X-coords[0])+sqr(Y-coords[1])));
- draw_figures;
- end;
- if (figure_state[3]=true) and (figure_state[1]=true) then
- begin
- coords[5]:=round(sqrt(sqr(X-coords[3])+sqr(Y-coords[4])));
- draw_figures;
- end;
- if (figure_state[2]=true) and (figure_state[0]=true) then
- begin
- coords[0]:=X+coords[2];
- coords[1]:=Y+coords[2];
- draw_figures;
- end;
- if (figure_state[2]=true) and (figure_state[1]=true) then
- begin
- coords[3]:=X+coords[5];
- coords[4]:=Y+coords[5];
- draw_figures;
- end;
- end;
- //------------------------------------------------------------------
- procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- figure_state[2]:=false;
- figure_state[3]:=false;
- end;
- //------------------------------------------------------------------
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- draw_figures;
- end;
- //------------------------------------------------------------------
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- coords[0]:=200;
- coords[1]:=100;
- coords[2]:=50;
- coords[3]:=100;
- coords[4]:=100;
- coords[5]:=50;
- draw_figures;
- end;
- //------------------------------------------------------------------
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement