Program laba5;
uses GraphABC, events;
const
windowsizex=1000;
windowsizey=660;
cornerx=1;
cornery=1;
statusheight=160;
field=10;
font=10;
noteplacey=30;
resultplacey=85;
placey=140;
placex=940;
statuscolor=clteal;
markcolor=clpurple;
rectanglex1=225;
rectangley1=285;
rectanglex2=775;
rectangley2=545;
colornumber=5;
sizenumber=3;
shapenumber=4;
smalllength=20;
middlelength=40;
biglength=60;
arrayborder=100;
type
figure=record
x,y,color,shape,size:integer;
end;
var
mas:array[1..arrayborder] of figure;
i,number,borderx,bordery:integer;
result:string;
procedure main;
begin
rectangle(cornerx,cornery,windowsizex,statusheight);
setbrushcolor(statuscolor);
fillrect(cornerx,cornery,windowsizex,statusheight);
setfontsize(font);
setfontcolor(clblack);
setfontstyle(fsBold);
textout(field,field,'Добро пожаловать в программу вычисления количества красных фигур внутри прямоугольника!');
textout(field,noteplacey,'Нажмите "Начать" для запуска программы или "Выход" для завершения работы.');
textout(field,resultplacey,'Фигур внутри прямоугольника: ');
textout(field,placey,'Начать');
textout(placex,placey,'Выход');
setbrushstyle(bsclear);
setpencolor(clblack);
rectangle(rectanglex1,rectangley1,rectanglex2,rectangley2);
end;
procedure pen;
begin
case mas[i].color of
0: setpencolor(clred);
1: setpencolor(clgreen);
2: setpencolor(clblue);
3: setpencolor(clyellow);
4: setpencolor(clgray);
end;
end;
procedure drawcross(x1,y1,size1,pen1:integer);
begin
pen;
line(x1-size1,y1,x1+size1,y1);
line(x1,y1-size1,x1,y1+size1);
end;
procedure drawskewcross(x1,y1,size1,pen1:integer);
var
n:integer;
begin
n:=trunc(size1*0.7);
pen;
line(x1-n,y1-n,x1+n,y1+n);
line(x1-n,y1+n,x1+n,y1-n);
end;
procedure drawcircle(x1,y1,size1,pen1:integer);
begin
pen;
setbrushstyle(bsclear);
circle(x1,y1,size1);
end;
procedure drawstar(x1,y1,size1,pen1:integer);
var
n:integer;
begin
n:=trunc(size1*0.7);
pen;
line(x1-n,y1-n,x1+n,y1+n);
line(x1-n,y1+n,x1+n,y1-n);
line(x1-size1,y1,x1+size1,y1);
line(x1,y1-size1,x1,y1+size1);
end;
procedure press(mousex,mousey,mmousey:integer);
var i:integer;
begin
if (mousex>=placex)and(mousex<=placex+45) and (mousey>=placey)and(mousey<=placey+font+5) then
begin
setbrushcolor(markcolor);
textout(placex,placey,'Выход');
closewindow;
end
else if (mousex>=field)and(mousex<=field+55) and (mousey>=placey)and(mousey<=placey+font+5) then
begin
ClearWindow;
main;
setbrushcolor(markcolor);
textout(field,placey,'Начать');
number:=0;
for i := 1 to arrayborder do
with mas[i] do
begin
size:=random(sizenumber);
case size of
0: size:=smalllength;
1: size:=middlelength;
2: size:=biglength;
end;
borderx:=windowsizex-2*size;
x:=random(borderx)+size;
bordery:=windowsizey-2*size-statusheight;
y:=random(bordery)+statusheight+size;
color:=random(colornumber);
shape:=random(shapenumber);
end;
for i:=1 to arrayborder do
begin
with mas[i] do
begin
case shape of
0: drawcross(x,y,size,color);
1: drawskewcross(x,y,size,color);
2: drawcircle(x,y,size,color);
3: drawstar(x,y,size,color);
end;
if (pencolor=clred)and(x-size>rectanglex1)and(x+size<rectanglex2) and (y-size>rectangley1)and(y+size<rectangley2) then number:=number+1;
end;
str(number,result);
setbrushcolor(statuscolor);
textout(field+235,resultplacey,result);
end;
end;
end;
begin
setwindowsize(windowsizex,windowsizey);
ClearWindow;
centerwindow;
main;
onmousedown:=press;
end.