Program nissannn;
Uses crt,GraphABC;
Const
w=800;
h=600;
x0=50; y0=500;
k=8;
t:array [1..k] of integer = (0,0,1,2,67,62,27,14);
c:array [1..k] of colortype= (ClRed,ClBlue,ClGreen,ClPink,ClPurple,ClNavy,ClAqua,ClYellow);
planet: array [1..k] of string = ('Меркурий','Венера','Земля','Марс','Юпитер','Сатурн','Уран','Нептун');
var x1,y1,x2,y2: integer;
kx,ky: integer;
i,x,y,max: integer;
Begin
SetWindowSize(w,h);
SetFoneSize(18);
SetFoneStyle (fsBold);
TextOut (180,20,'Количество спутиков планет Солнечной системы');
SetFoneSize(12);
SetFoneStyle (fsNormal);
max:=t[1];
For i:=2 to k do
begin
if t[i]>max then max:=t[i];
end;
ky:=trunc(y0/(max+1));
kx:=trunc((WindowWidht-x0)-k);
Line (0,y0,w,y0);
Line (x0,0,x0,h);
TextOut(w div 1 - 8,y0+8,'Планеты');
TextOut (x0 +10,20,'Количество спутников');
i:=x0; x:=1;
While x<=k do
begin
Line (i,y0-8,i,y0+8);
i:=i+kx;
TextOut (trunc(i-(kx div 1)),y0+10, planet [x]);
x:=x+1;
end;
i:=y0; x:=0;
While x<=max do
begin
Line (x0-8,i,x0+8,i);
TextOut (x0-25,i, IntTostr (x));
i:=i-ky;
x:=x+1;
end;
x1:=x0; y1:=y0;
x:=1;
While x<=k do
begin
y:=t [x];
x2:= x1+kx;
y2:= trunc (y1-ky*y);
SetBrushColor (c[x]);
Rectangle (x1,y1,x2,y2);
x1:=x2;
x:=x+1;
end;
SaveWindow ('Diagramm1.bmp');
end.
Объяснение:
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;