Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TMainForm.DrawVertexes(Amount: Integer;var VertexCoords: VertexList);
- var
- I, X, Y: Integer;
- Center: Coords;
- CurrPhi, Phi: Extended;
- CurrCoords: Coords;
- begin
- VertexCoords := TList<Coords>.Create;
- Phi := (2 * Pi) / Amount;
- Center.X := Visualizer.Width div 2;
- Center.Y := Visualizer.Height div 2;
- with Visualizer.Canvas do
- begin
- Pen.Color := VERTEXES_COLOR;
- Pen.Width := 1;
- X := Center.X;
- Y := Center.Y;
- Font.Name := 'Segoe UI';
- Font.Style := [fsBold];
- Font.Color := VERTEXES_COLOR;
- Font.Height := FONT_SIZE;
- CurrPhi := 0;
- for I := 0 to Amount - 1 do
- begin
- Brush.Color := VERTEXES_COLOR;
- CurrPhi := CurrPhi + Phi;
- Y := Round(Center.Y - GRAPH_RAD * Sin(CurrPhi));
- X := Round(Center.X - GRAPH_RAD * Cos(CurrPhi));
- Ellipse(X - VERTEX_RAD, Y - VERTEX_RAD, X + VERTEX_RAD, Y + VERTEX_RAD);
- CurrCoords.X := X;
- CurrCoords.Y := Y;
- VertexCoords.Add(CurrCoords);
- Brush.Color := BACKGROUND_COLOR;
- if CurrPhi < Pi then
- TextOut(X - 5 , Y - 64, IntToStr(I + 1))
- else
- TextOut(X - 5, Y + 32, IntToStr(I + 1));
- end;
- end;
- end;
- procedure TMainForm.DrawLines(AdjMatrix: TMatrix; VertexCoords: VertexList);
- var
- I, J: Byte;
- InciedenceList: TList;
- Line: String;
- begin
- for I := 0 to High(AdjMatrix) do
- begin
- for J := 0 to High(AdjMatrix) do
- begin
- if AdjMatrix[I][J] = 1 then
- begin
- with Visualizer.Canvas do
- begin
- Pen.Color := VERTEXES_COLOR;
- Pen.Width := LINE_WIDTH;
- MoveTo(VertexCoords.Items[I].X, VertexCoords.Items[I].Y);
- LineTo(VertexCoords.Items[J].X, VertexCoords.Items[J].Y);
- end;
- end;
- end;
- end;
- end;
- procedure TMainForm.DrawGraph(AdjMatrix: TMatrix);
- var
- VertexCoords: VertexList;
- begin
- VertexCoords := TList<Coords>.Create;
- DrawVertexes(Length(AdjMatrix), VertexCoords);
- DrawLines(AdjMatrix, VertexCoords);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement