Круг и квадрат с возможностью менять цвета

Исходный код:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls;

type
  TForm1 = class(TForm)
    ColorDialog1: TColorDialog;
    MainMenu1: TMainMenu;
    figura1: TMenuItem;
    culoare1: TMenuItem;
    interior1: TMenuItem;
    exterior1: TMenuItem;
    aleator11: TMenuItem;
    selectate11: TMenuItem;
    aliator21: TMenuItem;
    selectate21: TMenuItem;
    patrat1: TMenuItem;
    cerc1: TMenuItem;
    Button1: TButton;
    procedure FormPaint(Sender: TObject);
    procedure cerc1Click(Sender: TObject);
    procedure patrat1Click(Sender: TObject);
    procedure aleator11Click(Sender: TObject);
    procedure selectate11Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure aliator21Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  f:boolean;
  culoare,culoare2:integer;
implementation

{$R *.dfm}

procedure TForm1.FormPaint(Sender: TObject);
begin
culoare:=clwhite;
culoare2:=clwhite;
form1.Canvas.pen.Width:=5;
end;

procedure TForm1.cerc1Click(Sender: TObject);
begin
  f:=true;
  form1.Canvas.Brush.Color:=clbtnface;
  form1.Canvas.pen.Color:=clbtnface;
  form1.Canvas.Rectangle(0,0,100,100);
  form1.Canvas.Brush.color:=culoare;
  form1.canvas.pen.Color:=culoare2;
  form1.Canvas.Ellipse(20,20,100,100);
end;

procedure TForm1.patrat1Click(Sender: TObject);
begin
f:=false;

  form1.Canvas.Brush.Color:=clbtnface;
  form1.Canvas.pen.Color:=clbtnface;
  form1.Canvas.Rectangle(0,0,100,100);
  form1.Canvas.Brush.color:=culoare;
  form1.canvas.pen.Color:=culoare2;
  form1.Canvas.rectangle(20,20,100,100);
end;

procedure TForm1.aleator11Click(Sender: TObject);
var r,g,b:integer;
begin
r:=random(255);g:=random(255);b:=random(255);
culoare:=rgb(r,g,b);
form1.Canvas.Brush.Color:=clbtnface;
form1.Canvas.Pen.color:=clbtnface;
if f then begin
form1.Canvas.Rectangle(0,0,100,100);
form1.Canvas.Brush.Color:=culoare;
form1.Canvas.Pen.Color:=culoare2;
form1.Canvas.Ellipse(20,20,100,100);
end else begin
form1.Canvas.Rectangle(0,0,100,100);
form1.Canvas.Brush.Color:=culoare;
form1.canvas.pen.Color:=culoare2;
form1.Canvas.Rectangle(20,20,100,100);
end;

end;

procedure TForm1.selectate11Click(Sender: TObject);
begin
if colordialog1.Execute then culoare:=colordialog1.color;
form1.Canvas.Brush.Color:=clbtnface;
form1.Canvas.Pen.Color:=clbtnface;
if f then begin
form1.Canvas.Rectangle(0,0,100,100);
form1.Canvas.Brush.Color:=culoare;
form1.Canvas.Pen.Color:=culoare2;
form1.Canvas.Rectangle(20,20,100,100);
end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.aliator21Click(Sender: TObject);
var r,g,b:
begin
r:=random(255);g:=random(255);b:=random(255);
culoare:=rgb(r,g,b);
form1.Canvas.Brush.Color:=clbtnface;
form1.Canvas.Pen.color:=clbtnface;
if f then begin
form1.Canvas.Rectangle(0,0,100,100);
form1.Canvas.Brush.Color:=culoare;
form1.Canvas.Pen.Color:=culoare2;
form1.Canvas.Ellipse(20,20,100,100);
end else begin
form1.Canvas.Rectangle(0,0,100,100);
form1.Canvas.Brush.Color:=culoare;
form1.canvas.pen.Color:=culoare2;
form1.Canvas.Rectangle(20,20,100,100);
end;

end;

end.

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *