Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit DrawSquareUnit;
- interface
- uses
- System.SysUtils, Classes, System.Generics.Collections, Math, Vcl.ExtCtrls, Vcl.Graphics, MagicBoxUnit, ShowSquareUnit;
- type
- SquarePrinter = class
- class procedure drawSquare(var Square: TSquare; var Image: TImage); static;
- class procedure printText(Text: string; var Image: TImage); static;
- class procedure clear(var Image: TImage); static;
- end;
- implementation
- const
- XTextOffset = 350;
- YTextOffset = 3;
- XTableOffset = 10;
- YTableOffset = 40;
- class procedure SquarePrinter.drawSquare(var Square: TSquare; var Image: TImage);
- var
- CellWidth, CellHeight, i, j, YValueOffset, XValueOffset, Size, EndNumber: integer;
- begin
- CellWidth := trunc(1000 / length(Square));
- CellHeight := trunc(470 / length(Square));
- XValueOffset := trunc(CellWidth / 4);
- YValueOffset := trunc(CellHeight / 3.3);
- Size := length(Square);
- EndNumber := Size - 1;
- with Image do
- begin
- Canvas.Pen.Color := clBlue;
- Canvas.Pen.Style := psSolid;
- Canvas.Pen.Width := 2;
- Canvas.Font.Size := trunc(150 / Size);
- for i := 0 to Size do
- begin
- Canvas.MoveTo(XTableOffset + i * CellWidth, YTableOffset);
- Canvas.LineTo(XTableOffset + i * CellWidth, YTableOffset + Size * CellHeight);
- end;
- for i := 0 to Size do
- begin
- Canvas.MoveTo(XTableOffset, YTableOffset + i * CellHeight);
- Canvas.LineTo(XTableOffset + Size * CellWidth, YTableOffset + i * CellHeight);
- end;
- for i := 0 to EndNumber do
- begin
- for j := 0 to EndNumber do
- Canvas.TextOut(XTableOffset + j * CellWidth + XValueOffset, YTableOffset + i * CellHeight + YValueOffset, intToStr(Square[i][j]));
- end;
- end;
- end;
- class procedure SquarePrinter.printText(Text: string; var Image: TImage);
- begin
- with Image do
- begin
- Canvas.Font.Size := 14;
- Canvas.TextOut(XTextOffset, YTextOffset, Text);
- end;
- end;
- class procedure SquarePrinter.clear(var Image: TImage);
- begin
- with Image do
- begin
- Canvas.Pen.Color := clwhite;
- Canvas.brush.Color := clwhite;
- Canvas.rectangle(0, 0, Image.Width - 1, Image.Height - 1);
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement