Advertisement
Vanya_Shestakov

Untitled

Apr 30th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. procedure TMainForm.DrawVertexes(Amount: Integer;var VertexCoords: VertexList);
  2. var
  3. I, X, Y: Integer;
  4. Center: Coords;
  5. CurrPhi, Phi: Extended;
  6. CurrCoords: Coords;
  7. begin
  8. VertexCoords := TList<Coords>.Create;
  9. Phi := (2 * Pi) / Amount;
  10. Center.X := Visualizer.Width div 2;
  11. Center.Y := Visualizer.Height div 2;
  12. with Visualizer.Canvas do
  13. begin
  14. Pen.Color := VERTEXES_COLOR;
  15. Pen.Width := 1;
  16. X := Center.X;
  17. Y := Center.Y;
  18. Font.Name := 'Segoe UI';
  19. Font.Style := [fsBold];
  20. Font.Color := VERTEXES_COLOR;
  21. Font.Height := FONT_SIZE;
  22. CurrPhi := 0;
  23. for I := 0 to Amount - 1 do
  24. begin
  25. Brush.Color := VERTEXES_COLOR;
  26. CurrPhi := CurrPhi + Phi;
  27. Y := Round(Center.Y - GRAPH_RAD * Sin(CurrPhi));
  28. X := Round(Center.X - GRAPH_RAD * Cos(CurrPhi));
  29. Ellipse(X - VERTEX_RAD, Y - VERTEX_RAD, X + VERTEX_RAD, Y + VERTEX_RAD);
  30. CurrCoords.X := X;
  31. CurrCoords.Y := Y;
  32. VertexCoords.Add(CurrCoords);
  33. Brush.Color := BACKGROUND_COLOR;
  34. if CurrPhi < Pi then
  35. TextOut(X - 5 , Y - 64, IntToStr(I + 1))
  36. else
  37. TextOut(X - 5, Y + 32, IntToStr(I + 1));
  38. end;
  39. end;
  40. end;
  41.  
  42. procedure TMainForm.DrawLines(AdjMatrix: TMatrix; VertexCoords: VertexList);
  43. var
  44. I, J: Byte;
  45. InciedenceList: TList;
  46. Line: String;
  47. begin
  48. for I := 0 to High(AdjMatrix) do
  49. begin
  50. for J := 0 to High(AdjMatrix) do
  51. begin
  52. if AdjMatrix[I][J] = 1 then
  53. begin
  54. with Visualizer.Canvas do
  55. begin
  56. Pen.Color := VERTEXES_COLOR;
  57. Pen.Width := LINE_WIDTH;
  58. MoveTo(VertexCoords.Items[I].X, VertexCoords.Items[I].Y);
  59. LineTo(VertexCoords.Items[J].X, VertexCoords.Items[J].Y);
  60. end;
  61. end;
  62. end;
  63. end;
  64. end;
  65.  
  66. procedure TMainForm.DrawGraph(AdjMatrix: TMatrix);
  67. var
  68. VertexCoords: VertexList;
  69. begin
  70. VertexCoords := TList<Coords>.Create;
  71. DrawVertexes(Length(AdjMatrix), VertexCoords);
  72. DrawLines(AdjMatrix, VertexCoords);
  73. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement