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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
| program prog;
uses Graph,crt,Mouse;
procedure GraphInit;
var grMode,grDriver,ErrCode,b,t,a:integer; ch,ch1:char;
begin
grDriver:=Detect;
InitGraph(grDriver, grMode, 'BP');
ErrCode:=GraphResult;
if ErrCode <> grOK then
begin
writeln('Error:', 'GraphErrormsg<ErrCode)');
readln;
halt;
end;
end;
{Функция мыши}
function ButtonPressed(x1,y1,x2,y2:integer):boolean; {функция на проверку нажатия кнопки}
var Mk,Ml:integer; ctr:integer;
begin
GetMouse;
ButtonPressed:=(but=1)and(m>x1)and(m<x2)and(n>y1)and(n<y2);
end;
{Функция f(x)}
function Fx2(x:real):real;
var a,b:integer;
begin
Fx2:=a*cos(x)+b*x;
end;
{Функция F(x)}
Function Fx1(x:real):real;
var a,b:integer;
begin
Fx1:=a*(cos(x)/sin(x))+b;
end;
{Кнопки}
procedure Key(a1,b1,a2,b2,c:integer; st:string);
begin
SetFillStyle(1,4);
Bar(a1,b1,a2,b2);
SetColor(c);
OutTextXy(a1+20,((b1+b2) div 2) ,st)
end;
{График}
procedure GraphTable;
begin
Setfillstyle(1,15);
bar(200,40,620,390);
setColor(8);
SetLineStyle(0,0,ThickWidth);
Rectangle(180,10,620,396);
SetColor(0);
SetLineStyle(2,0,ThickWidth);
line(400,10,400,390);
line(180,220,620,220);
OutTextXy(610,230,'X');
OutTextXy(385,230,'0');
OutTextXy(385,15,'Y');
SetLineStyle(0,0,ThickWidth);
end;
{Интерфейс}
procedure inter;
begin
SetFillStyle(1,2);
bar(0,0,639,479);
Key(20,410,160,460,1,'NEW');
Key(200,410,320,460,1,'TABLE');
Key(350,410,470,460,1,'GRAPH');
Key(500,410,620,460,1,'EXIT');
Graphtable;
{Таблица}
SetLineStyle(0,0,ThickWidth);
setColor(1);
Rectangle(20,40,160,335);
line(20,65,160,65);
line(90,41,90,335);
{Переменные}
setColor(1);
Rectangle(20,345,160,390);
setcolor(0);
OutTextXy(25,360,'a=');
OutTextXy(25,375,'b=');
setcolor(2);
end;
{Процедура кнопки TAB}
var x1,x2,y1,y2,i,k,a,b,t:integer; x,y:real; st1,st2:string;
procedure Table;
begin
st1:='';
x1:=42; y1:=54; x:=-10; x2:=105; y2:=54;
for i:=1 to 21 do
begin
str(x:6:1,st1);
y1:=y1+13;
y2:=y2+13;
setfillstyle(1,2);
bar(x2-10,y2,x2+30,y2+6);
setcolor(0);
outtextXy(x1,y1,st1);
if t=2 then
y:=Fx1(x);
if t=1 then
y:=Fx2(x);
str(y:4:1,st2);
setcolor(0);
outtextXy(x2,y2,st2);
setcolor(1);
SetlineStyle(0,0,normwidth);
line(20,y1+10,160,y2+10);
x:=x+1;
end;
end;
{Процедура ввода}
var chr:char; sc,h:integer;
procedure New(x01,x02:integer; str:string; h:real);
begin
SetfillStyle(1,15);
bar(20,2,160,32);
setcolor(4);
OutTextXY(24,16,'Введите переменные');
setcolor(0);
rectangle(20,2,160,32);
rectangle(20,345,160,390);
str:='';
repeat
chr:=readkey;
case chr of
'0'..'9','.','-':
if length(str)<6 then
begin
str:=str+chr;
end;
#8:begin
SetFillStyle(1,15);
bar(x01-5,x02-5,x01+40,x02+6);
Delete(str,length(str),6);
end;
end;
setfillstyle(1,15);
bar(x01-5,x02-5,x01+40,x02+6);
setcolor(0);
OutTextXy(x01,x02,str);
until chr=#13;
if h = 1 then
begin
val(str,a,sc);
end;
if h = 2 then
begin
val(str,b,sc);
end;
SetfillStyle(1,0);
bar(20,2,160,32);
setcolor(0);
rectangle(20,2,160,32);
setcolor(8);
rectangle(20,345,160,390);
Table;
end;
{Процедура кнопок в окошке}
procedure intOkno;
var tu,t:integer; ch3:char; ex:boolean;
begin
repeat
if keypressed then begin
ch3:=readkey;
if ch3=#0 then
ch3:=readkey;
case ch3 of
{Вверх}
#72:begin t:=t-1;
if t = 1 then
begin
setLineStyle(0,0,ThickWidth);
SetColor(8);
rectangle(105,155,445,175);
setcolor(12);
rectangle(105,180,445,205);
end;
if t <= 0 then begin t:=2; end;
if t = 2 then
begin
Setlinestyle(0,0,ThickWidth);
SetColor(12);
rectangle(105,155,445,175);
setcolor(8);
rectangle(105,180,445,205);
end;
end;
{Вниз}
#80:begin t:=t+1;
if t > 2 then begin t:=1; end;
if t = 1 then
begin
setLineStyle(0,0,ThickWidth);
SetColor(8);
rectangle(105,155,445,175);
setcolor(12);
rectangle(105,180,445,205); end;
if t = 2 then
begin
Setlinestyle(0,0,ThickWidth);
SetColor(12);
rectangle(105,155,445,175);
setcolor(8);
rectangle(105,180,445,205);
end;
end;
#13:begin
if t = 1 then begin t:=1; ex:=true; end;
if t = 2 then begin t:=2; ex:=true; end;
end;
end;
end;
until ex=true;
end;
{Процедура окна}
procedure okno;
Var p:pointer; size:word;
begin
size:=ImageSize(100,150,450,210);
GetMem(p,size);
GetImage(100,150,450,250,p^);
SetFillStyle(1,7);
bar(100,150,450,210);
SetColor(0);
Rectangle(101,151,449,209);
Rectangle(105,155,445,175);
Rectangle(105,180,445,205);
SetColor(0);
OutTextXy(110,162,'F(X)=a*cos(x)+b*x');
OutTextXy(110,187,'F(X)=a*ctg(x)+b');
intOkno;
PutImage(100,150,p^,0);
FreeMem(p,size);
Table;
end;
{Процедура кнопки граф}
procedure DrawGraph;
var y:integer; dx,x,xx,a,b:real;
begin
SetViewPort(180,10,620,396, Clipon);
x:=-10;
xx:=0;
dx:=20/4200;
while x<10 do
begin
if t=2 then
PutPixel(round(xx),178-round(fx1(x)),4);
if t=1 then
PutPixel(round(xx),178-round(fx2(x)),15);
x:=x+dx;
xx:=xx+0.1;
end;
SetViewPort(0,0,639,479,Clipon);
end;
var f:integer;
{Клик мышью}
var ch2:char; ex:boolean;
Procedure mouseclick;
begin
repeat
if keypressed then begin
ch2:=readkey;
if ch2=#0 then ch2:=readkey;
case ch2 of
'N','n':begin New(55,360,'20',1);
New(55,375,'15',2); end;
'T','t':begin Okno; end;
'G','g':begin DrawGraph; end;
'E','e':begin CloseGraph; halt; end;
{Изменение кнопок при нажатии стрелок}
{Стрелка вправо}
#77:begin
f:=f+1;
if f = 5 then begin f:=1;
if f = 1 then begin
setcolor(0);
Rectangle(20,410,160,460);
Setcolor(1);
Rectangle(500,410,620,460);
Rectangle(350,410,470,460);
Rectangle(200,410,320,460); end; end;
if f = 2 then begin
setcolor(0);
Rectangle(200,410,320,460);
Setcolor(1);
Rectangle(20,410,160,460);
Rectangle(500,410,620,460);
Rectangle(350,410,470,460)end;
if f = 3 then begin
setcolor(0);
Rectangle(350,410,470,460);
Setcolor(1);
Rectangle(200,410,320,460);
Rectangle(20,410,160,460);
Rectangle(500,410,620,460);end;
if f = 4 then begin
setcolor(0);
Rectangle(500,410,620,460);
Setcolor(1);
Rectangle(350,410,470,460);
Rectangle(200,410,320,460);
Rectangle(20,410,160,460); end;
end;
{Стрелка влево}
#75:begin
f:=f-1;
if f = 1 then begin
setcolor(0);
Rectangle(20,410,160,460);
Setcolor(1);
Rectangle(500,410,620,460);
Rectangle(350,410,470,460);
Rectangle(200,410,320,460); end;
if f = 2 then begin
setcolor(0);
Rectangle(200,410,320,460);
Setcolor(1);
Rectangle(20,410,160,460);
Rectangle(500,410,620,460);
Rectangle(350,410,470,460)end;
if f = 3 then begin
setcolor(0);
Rectangle(350,410,470,460);
Setcolor(1);
Rectangle(200,410,320,460);
Rectangle(20,410,160,460);
Rectangle(500,410,620,460);end;
if f = 0 then begin f:=4;
if f = 4 then begin
setcolor(0);
Rectangle(500,410,620,460);
Setcolor(1);
Rectangle(350,410,470,460);
Rectangle(200,410,320,460);
Rectangle(20,410,160,460); end; end;
end;
#13:begin
if f=4 then begin CloseGraph; halt; end;
if f=3 then begin DrawGraph; end;
if f=2 then begin okno; end;
if f=1 then begin New(55,360,'20',1);
New(55,375,'15',2); end;
{#13}end;
end;
end;
if Buttonpressed(500,410,620,460) then begin ex:=true; end;
if Buttonpressed(350,410,470,460) then begin DrawGraph; end;
if Buttonpressed(20,410,160,460) then begin New(55,360,'20',1);
New(55,375,'15',2); end;
if Buttonpressed(200,410,320,460) then begin okno; end;
until ex=true;
closegraph; halt;
end;
{Body}
begin
GraphInit;
InitMouse;
inter;
SetMouseYRange(0,480);
Showmouse;
mouseclick;
Showmouse;
end. |