-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1.pas
More file actions
83 lines (70 loc) · 2.3 KB
/
Lab1.pas
File metadata and controls
83 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
uses Graphabc;
var
ftype, a, b: integer;
procedure Dialogue(); //Задаём вопросики
begin
Writeln('Выберите функцию:');
Writeln('1.sin(x)');
Writeln('2.x^2');
Writeln('3.x^3');
Read(ftype);
ClearWindow();
Writeln('Задайте диапазон значений:');
Read(a, b);
ClearWindow();
end;
function ChoiseFunc(f: integer; x: real): real; // Выбираем функцию
begin
if (f = 1) then
ChoiseFunc := Sin(x)
else
if(f = 2) then
ChoiseFunc := x * x
else
if(f = 3) then
ChoiseFunc := x * x * x
else
exit;
end;
function MinNum(a, b, ftype: integer): integer; //Cчитаем минимум функции
var
min: real;
begin
min := MaxInt;
for var i := a to b do
if ChoiseFunc(ftype, i) < min then min := ChoiseFunc(ftype, i);
MinNum := Round(min);
end;
function MaxNum(a, b, ftype: integer): integer; //Cчитаем максимум функции
var
max: real;
begin
max := -MaxInt;
for var i := a to b do
if ChoiseFunc(ftype, i) > max then max := ChoiseFunc(ftype, i);
MaxNum := Round(max);
end;
procedure DrawGraph(a, b, ftype: integer); //Рисуем функцию
begin
SetWindowWidth(500);
SetWindowHeight(500);
var h := (WindowHeight()) / (Abs(a) + Abs(b)); //Множитель приближения по горизонтали
var centx := (a + b) div 2; // Центр отрисованного отрезка фунцкии по горизонтали
var w := (WindowWidth()) / ((Abs(MinNum(a, b, ftype)) + Abs(MaxNum(a, b, ftype)))); //Множитель приближения по вертикали
SetCoordinateOrigin((WindowWidth() div 2) - (centx * Round(h)), Round((MaxNum(a, b, ftype)) * w));
Line(0, -WindowWidth(), 0, WindowWidth); // вертикальная линия
Line(-WindowHeight(), 0, WindowHeight(), 0);// горизонтальная линия
var hn := (Abs(a) + Abs(b)) / 500;//
var xn := a + hn;
var xn2 := a / 1;
for var i := Round(a * h) + 1 to Round(b * h) do
begin
Line(i - 1, Round(-ChoiseFunc(ftype, xn2) * w), i, -Round(ChoiseFunc(ftype, xn) * w));
xn += hn;
xn2 += hn;
end;
end;
begin
Dialogue();
DrawGraph(a, b, ftype);
end.