Объяснение:
uses GraphABC;
const
Path = 'C:\Ilya\AlgoРитмы\Sankt-Peterburg.txt';
DisplacementX = 10;
DisplacementY = -10;
begin
SetWindowIsFixedSize(true);
var H := Window.Height;
var A := ReadAllText(Path).Replace(',', '.').ToReals();
var StepX := Window.Width / (A.Count - 1);
var Min := Abs(A.Min);
var Max := A.Max() + Min;
var B := A.Select((x, i) -> (x, Round(StepX * i), Round(H - (A[i] + Min) / Max * H))).ToList();
for var i := 0 to B.Count - 2 do
var c := Round(255 - (B[i].Item3 + B[i].Item3) * 0.5 / H * 255);
SetPenColor(RGB(0, c, c));
SetBrushColor(RGB(0, c, c));
Polygon(Arr(new Point(B[i].Item2, H), new Point(B[i].Item2, B[i].Item3),
new Point(B[i + 1].Item2, B[i + 1].Item3), new Point(B[i + 1].Item2, H)));
end;
SetFontColor(clBlack);
SetBrushColor(ARGB(200, 255, 255, 255));
for var i := 0 to B.Count - 1 do
TextOut(B[i].Item2 + DisplacementX, B[i].Item3 + DisplacementY, FloatToStr(B[i].Item1));
end.
Круговая диаграмма
Комментарии к коду [показать]
N = 5;
R = 150;
K = 0.7;
var
A: array of integer;
Angle: real;
SetWindowSize(500, 500);
var W := Window.Width div 2;
var H := Window.Height div 2;
SetLength(A, N);
for var i := 0 to N - 1 do
Readln(A[i]);
var Sum := A.Sum();
SetPenWidth(2);
var R2 := R * K;
var ang := Round(A[i] / Sum * 360);
SetBrushColor(clRandom());
Pie(W, H, R, Round(Angle), Round(Angle - ang));
var ang2 := DegToRad(360 - Angle + ang / 2);
SetBrushColor(clWhite);
TextOut(Round(W + R2 * Cos(ang2)), Round(H + R2 * Sin(ang2)), Format('{0} [~{1}%]', A[i], Round(A[i] / Sum * 100)));
Angle -= ang;
Объяснение:
uses GraphABC;
const
Path = 'C:\Ilya\AlgoРитмы\Sankt-Peterburg.txt';
DisplacementX = 10;
DisplacementY = -10;
begin
SetWindowIsFixedSize(true);
var H := Window.Height;
var A := ReadAllText(Path).Replace(',', '.').ToReals();
var StepX := Window.Width / (A.Count - 1);
var Min := Abs(A.Min);
var Max := A.Max() + Min;
var B := A.Select((x, i) -> (x, Round(StepX * i), Round(H - (A[i] + Min) / Max * H))).ToList();
for var i := 0 to B.Count - 2 do
begin
var c := Round(255 - (B[i].Item3 + B[i].Item3) * 0.5 / H * 255);
SetPenColor(RGB(0, c, c));
SetBrushColor(RGB(0, c, c));
Polygon(Arr(new Point(B[i].Item2, H), new Point(B[i].Item2, B[i].Item3),
new Point(B[i + 1].Item2, B[i + 1].Item3), new Point(B[i + 1].Item2, H)));
end;
SetFontColor(clBlack);
SetBrushColor(ARGB(200, 255, 255, 255));
for var i := 0 to B.Count - 1 do
TextOut(B[i].Item2 + DisplacementX, B[i].Item3 + DisplacementY, FloatToStr(B[i].Item1));
end.
Круговая диаграмма
Комментарии к коду [показать]
uses GraphABC;
const
N = 5;
R = 150;
K = 0.7;
var
A: array of integer;
Angle: real;
begin
SetWindowIsFixedSize(true);
SetWindowSize(500, 500);
var W := Window.Width div 2;
var H := Window.Height div 2;
SetLength(A, N);
for var i := 0 to N - 1 do
Readln(A[i]);
var Sum := A.Sum();
SetPenWidth(2);
var R2 := R * K;
for var i := 0 to N - 1 do
begin
var ang := Round(A[i] / Sum * 360);
SetBrushColor(clRandom());
Pie(W, H, R, Round(Angle), Round(Angle - ang));
var ang2 := DegToRad(360 - Angle + ang / 2);
SetBrushColor(clWhite);
TextOut(Round(W + R2 * Cos(ang2)), Round(H + R2 * Sin(ang2)), Format('{0} [~{1}%]', A[i], Round(A[i] / Sum * 100)));
Angle -= ang;
end;
const
W = 600;
H = 600;
function F(x: real): real;
begin
F := sqr(x);
end;
var
x0, y0, x, y, xLeft, yLeft, xRight, yRight: integer;
a, b, fmin, fmax, x1, y1, mx, my: real;
begin
window.Init(0, 0, 800, 500, clwhite);
window.IsFixedSize := true;
xRight := 590;
yRight := 590;
a := -15;
b := 6;
fmin := -10;
fmax := 20;
mx := (xRight - xLeft) / (b - a);
my := (yRight - yLeft) / (fmax - fmin);
x0 := 380;
y0 := 490;
x1 := a;
while x1 <= b do
begin
y1 := F(x1);
x := x0 + round(x1 * mx);
y := y0 - round(y1 * my);
if (y >= 10) and (y <= 590) then SetPixel(x, y, clblack);
x1 := x1 + 0.001 ;
end;
end.