Advertisement
believe_me

Untitled

Apr 5th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.33 KB | None | 0 0
  1. unit DrawSquareUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.     System.SysUtils, Classes, System.Generics.Collections, Math, Vcl.ExtCtrls, Vcl.Graphics, MagicBoxUnit, ShowSquareUnit;
  7.  
  8. type
  9.     SquarePrinter = class
  10.     class procedure drawSquare(var Square: TSquare; var Image: TImage); static;
  11.     class procedure printText(Text: string; var Image: TImage); static;
  12.     class procedure clear(var Image: TImage); static;
  13.     end;
  14.  
  15.  
  16. implementation
  17.  
  18.  
  19. const
  20.     XTextOffset = 350;
  21.     YTextOffset = 3;
  22.     XTableOffset = 10;
  23.     YTableOffset = 40;
  24.  
  25.  
  26. class procedure SquarePrinter.drawSquare(var Square: TSquare; var Image: TImage);
  27.  
  28. var
  29.     CellWidth, CellHeight, i, j, YValueOffset, XValueOffset, Size, EndNumber: integer;
  30.  
  31. begin
  32.     CellWidth := trunc(1000 / length(Square));
  33.     CellHeight := trunc(470 / length(Square));
  34.     XValueOffset := trunc(CellWidth / 4);
  35.     YValueOffset := trunc(CellHeight / 3.3);
  36.     Size := length(Square);
  37.     EndNumber := Size - 1;
  38.  
  39.  
  40.     with Image do
  41.     begin
  42.         Canvas.Pen.Color := clBlue;
  43.         Canvas.Pen.Style := psSolid;
  44.         Canvas.Pen.Width := 2;
  45.         Canvas.Font.Size := trunc(150 / Size);
  46.  
  47.         for i := 0 to Size do
  48.         begin
  49.             Canvas.MoveTo(XTableOffset + i * CellWidth, YTableOffset);
  50.             Canvas.LineTo(XTableOffset + i * CellWidth, YTableOffset + Size * CellHeight);
  51.         end;
  52.         for i := 0 to Size do
  53.         begin
  54.             Canvas.MoveTo(XTableOffset, YTableOffset + i * CellHeight);
  55.             Canvas.LineTo(XTableOffset + Size * CellWidth, YTableOffset + i * CellHeight);
  56.         end;
  57.         for i := 0 to EndNumber do
  58.         begin
  59.             for j := 0 to EndNumber do
  60.                 Canvas.TextOut(XTableOffset + j * CellWidth + XValueOffset, YTableOffset + i * CellHeight + YValueOffset, intToStr(Square[i][j]));
  61.         end;
  62.  
  63.     end;
  64. end;
  65.  
  66.  
  67. class procedure SquarePrinter.printText(Text: string; var Image: TImage);
  68.  
  69. begin
  70.     with Image do
  71.     begin
  72.         Canvas.Font.Size := 14;
  73.         Canvas.TextOut(XTextOffset, YTextOffset, Text);
  74.     end;
  75. end;
  76.  
  77.  
  78. class procedure SquarePrinter.clear(var Image: TImage);
  79.  
  80. begin
  81.     with Image do
  82.     begin
  83.         Canvas.Pen.Color := clwhite;
  84.         Canvas.brush.Color := clwhite;
  85.         Canvas.rectangle(0, 0, Image.Width - 1, Image.Height - 1);
  86.     end;
  87. end;
  88.  
  89.  
  90. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement