uses GraphABC;
type Shape = auto class x, y: integer; color: GraphABC.Color;
procedure Draw(); abstract;
end;
Rectangle = class(Shape)
x1, y1: integer;
constructor Create(x, y, x1, y1: integer; color: GraphABC.Color);
begin
self.x := x;
self.x1 := x1;
self.y := y;
self.y1 := y1;
self.color := color;
end;
procedure Draw(); override;
begin
brush.Color := color;
GraphABC.Rectangle(x, y, x1, y1);
brush.Color := GraphABC.Color.Transparent;
end;
end;
Circle = class(Shape)
r: integer;
constructor Create(x, y, r: integer; color: GraphABC.Color);
begin
self.x := x;
self.y := y;
self.r := r;
self.color := color;
end;
procedure Draw(); override;
begin
brush.Color := color;
GraphABC.Circle(x, y, r);
brush.Color := GraphABC.Color.Transparent;
end;
end;
Line = class(Shape)
p1,p2,o1,o2: integer;
constructor Create( p1,p2,o1,o2: integer; color: GraphABC.Color);
begin
self.p1 := p1;
self.o1 := o1;
self.p2 := p2;
self.o2 := o2;
self.color := color;
end;
procedure Draw(); override;
begin
brush.Color := color;
GraphABC.Line( p1,p2,o1,o2);
brush.Color := GraphABC.Color.Transparent;
end;
end;
Triangle = class(Shape)
x1, y1, x2, y2: integer;
constructor Create(x, y, x1, y1, x2, y2: integer; color: GraphABC.Color);
begin
self.x := x;
self.x1 := x1;
self.x2 := x2;
self.y := y;
self.y1 := y1;
self.y2 := y2;
self.color := color;
end;
procedure Draw(); override;
begin
brush.Color := color;
var points := new GraphABC.Point[3](new GraphABC.Point(x, y),
new GraphABC.Point(x1, y1),
new GraphABC.Point(x2, y2));
GraphABC.Polygon(points);
brush.Color := GraphABC.Color.Transparent;
end;
end;
function ChooseColor(color_name: string): GraphABC.Color; begin case color_name of ’красный’: result := GraphABC.Color.Red; ‘оранжевый’: result := GraphABC.Color.Orange; ‘желтый’: result := GraphABC.Color.Yellow; ‘зеленый’: result := GraphABC.Color.Green; ‘голубой’: result := GraphABC.Color.LightCyan; ‘синий’: result := GraphABC.Color.Blue; ‘фиолетовый’: result := GraphABC.Color.Magenta;
end;
end;
function ChooseFigure(figure_type: string; color: GraphABC.Color): Shape; begin case figure_type of ’прямоугольник’: result := new Rectangle(500, 400, 170, 170, color); ‘квадрат’: result := new Rectangle(200, 200, 400, 400, color); ‘круг’: result := new Circle(320, 250, 100, color); ‘линия’: result := new Line(300,100,400,100,color); ‘треугольник’: result := new Triangle(250, 350, 300, 250, 350, 350, color); end; end; begin writeLn(‘Программа содержит модуль graph и классы геометрических фигур’); writeLn(‘Для продолжения нажмите entr’); readln();
begin clearwindow; writeLn(‘Напишите один из семи цветов спектора:’); writeLn(’’); writeLn(‘1-красный’); writeLn(‘2-оранжевый’); writeLn(‘3-желтый’); writeLn(‘4-зеленый’); writeLn(‘5-голубой’); writeLn(‘6-синий’); writeLn(‘7-фиолетовый’); writeLn(’’); var color_name := ReadString(); var color := ChooseColor(color_name); clearwindow; writeLn(‘Выберите одну их четырех фигур:’); writeLn(’’); writeLn(‘1-треугольник’); writeLn(‘2-круг’); writeLn(‘3-квадрат’); writeLn(‘4-прямоугольник’); writeLn(‘5-линия’); var figure_type := ReadString(); var figure := ChooseFigure(figure_type, color); clearwindow; figure.Draw();
end; end.