-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafiek.pas
1445 lines (1399 loc) · 47.8 KB
/
grafiek.pas
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Program DosPlot;
{
DosPlot - a dos program that plots graphs
Copyright (C) 2004 Gert van den Berg
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To do list:
-----------
3. Add separate X and Y scale
5b. Translate source to English
6. Add support for equations with custom subject (e.g. x^3+y^3=6xy
8. Add screen shot support
10. Add comments to source
11. Port to windows
)
Notes on compiling this program:
--------------------------------
Free Pascal:
------------
Set target to DOS(GO32v2), WIN32 might work as well. Do not run WIN32
version from IDE.
Turbo/Borland Pascal:
---------------------
Free Pascal compilation is recommended since it generates faster 32bit
code
BP only: Set target to REAL MODE or "Protected mode"
}
(* Code for easy copy and pasting
{$IFDEF EXCEPT}
try
except
end;
{$ELSE}
{$ENDIF}
*)
{$F+}{$B-}{$N+}{$E-}{$G+}{$R-}
{$IFDEF FPC}
{$INLINE ON}
{$DEFINE EXCEPT} // Free Pascal het exception support.
// Delphi ook maar dit behoort NIE te werk NIE
{$MODE Delphi}
{$M 131072, 9000000}
{$GOTO ON}
{$ENDIF}
{$M 65520,0,655360}
Uses grafunit, pcalcexp, scrsave,crt
{$IFDEF WIN32},windows{$ENDIF}
{$IFDEF LINUX},ptcgraph{$ELSE},Graph{$ENDIF};
Type
{ coordintT = Record
x,y : longint;
End;
coordrealT = Record
x,y : extended;
End;{}
coordT = Record
x,y : longint;
realx,
realy : extended;
valid : boolean;
End;{}
CalcFuncT = Function (const p1 : extended;
const p2 : postfT;
var p3 : boolean) : extended;
const
small : extended = 1e-14;
large : extended = 1e10;
{----------------------------------------------------------------------------}
Function CalcRealY ( const x : extended;
const pf : postfT;
var error : boolean) : extended;
Begin
error := false;
{$IFDEF EXCEPT}
try // sorg dat nie exit op exception
try
calcRealy := CalcPostfix(pf,x,0,0);
except
calcrealy := 0;
error := true or (calcerror <> 0);
end;
except
error := true;
end;
{$ELSE}
calcRealy := CalcPostfix(pf,x,0,0);
if (calcerror <> 0) then
Begin
calcrealy := 0;
error := true;
End;
{$ENDIF}
End;
{----------------------------------------------------------------------------}
Function slope (const position : extended;
const postf : postfT;
var error : boolean) : extended; far;
{Returns and estimation of lim(x->position-)[postf]
Error = true if error calculating limit}
var
x : extended;
tmp : extended;
tmp2 : extended;
Begin
{$IFDEF EXCEPT}
try
{$ENDIF}
tmp := calcrealy(position,postf,error);
error := error or (CalcError <> 0);
If abs(tmp) > 1 then
tmp2 := small*tmp
else
tmp2 := small;
x := position + tmp2;
slope := (calcrealy(x,postf,error)-tmp)/tmp2;
{$IFDEF EXCEPT}
except
error := true;
end;
{$ENDIF}
error := error or (CalcError <> 0);
If Error then
slope := 0;
End;
{----------------------------------------------------------------------------}
Function leftvalue (const position : extended;
const postf : postft;
var error : boolean) : extended;
{Returns and estimation of lim(x->position-)[postf]
Error = true if error calculating limit}
var
x : extended;
Begin
x := position - small;
leftvalue := calcrealy(x,postf,error);
End;
{----------------------------------------------------------------------------}
Function rightvalue(const position : extended;
const postf : postft;
var error : boolean) : extended;
{Returns and estimation of lim(x->position+)[postf]
Error = true if error calculating limit}
var
x : extended;
Begin
x := position + small;
rightvalue := calcrealy(x,postf,error);
End;
{----------------------------------------------------------------------------}
Function limitvalue(const position : extended;
const postf : postft;
var error : boolean) : extended;
{Returns and estimation of lim(x->position)[postf]
Error = true if error calculating limit}
var
l,r : extended;
errorl,
errorr : boolean;
Begin
l := leftvalue (position,postf,errorl);
r := rightvalue(position,postf,errorr);
If (abs(l-r) < 1e-10) then
begin
limitvalue := (l+r)/2;
error := false;
end
else
error := true;
error := error or errorl or errorr;
End;
{----------------------------------------------------------------------------}
Function discontinuous(const min, max : extended;
const postf : postft;
var position : extended) : boolean;
{Return false if a function does not contain jump discontinuities between min
and max.
Position will contain position of discontinuity.
In order for this to work properly the gap between min and max must be
sufficiently small
Will return false if gradient is very large at cen or if postf(min/max/cen)
is undefined}
Function Disconrecur(min,max : extended) : boolean;
var
discon : boolean;
cen : extended; { x value of center}
miny,
maxy,
ceny : extended;
mleft,
mright,
mcen : extended;
error : boolean;
cenl,cenr : extended;
cenly,
cenry : extended;
mll,mlc,
mcr,mrr : extended;
dmp : boolean;
label funcend;
Begin
error := false;
discon := false;
cen := (min + max)/2;
if (cen = min) then
Begin
discon := false;
goto funcend;
End;
miny := limitvalue(min,postf,error);
if error then
Begin
position := min+small;
GOTO funcend;
end;
maxy := limitvalue (max,postf,error);
if error then
Begin
position := max-small;
GOTO funcend;
end;
ceny := limitvalue(cen,postf,error);
error := CalcResult <> 0;
if error then
Begin
position := cen;
GOTO funcend;
end;
{$IFDEF EXCEPT}
try
mleft := (ceny-miny)/(cen-min);
except
position := (cen+min)/2;
error := true;
end;
try
mright := (ceny-maxy)/(cen-max);
except
position := (cen+max)/2;
error := true;
end;
try
mcen := (maxy-miny)/(max-min);
except
position := cen;
error := true;
end;
{$ELSE}
if (cen - min) <> 0 then
mleft := (ceny-miny)/(cen-min)
else
Begin
error := true;
position := (cen + min)/2;
GOTO funcend;
End;
if (cen - max) <> 0 then
mright := (ceny-maxy)/(cen-max)
else
Begin
error := true;
position := (cen + max)/2;
GOTO funcend;
End;
if (max - min) <> 0 then
mcen := (maxy-miny)/(max-min)
else
Begin
error := true;
position := cen;
GOTO funcend;
End;
{$ENDIF}
if error then
GOTO funcend;
If ((mleft*mright > 0)and (mcen*mleft > 0) and (mcen*mright > 0)) then
Begin
discon := false;
error := false;
goto FuncEnd;
End
else
discon := true;
cenl := (cen+min)/2;
cenr := (cen+max)/2;
cenly := limitvalue(cenl,postf,error);
if error then
Begin
position := cenl;
GOTO funcend;
end;
cenry := limitvalue(cenr,postf,error);
if error then
Begin
position := cenr;
GOTO funcend;
end;
{$IFDEF EXCEPT}
try
mll := (miny-cenly)/(min-cenl);
except
position := (min+cenl)/2;
error := true;
end;
try
mlc := (ceny-cenly)/(cen-cenl);
except
position := (cenl+cen)/2;
error := true;
end;
try
mcr := (cenry-ceny)/(cenr-cen);
except
position := (cenr+cen)/2;
error := true;
end;
try
mrr := (cenry-maxy)/(cenr-max);
except
position := (cenr+cen)/2;
error := true;
end;
{$ELSE}
if ((cenl - min) <> 0) then
mll := (miny-cenly)/(min-cenl)
else
Begin
position := (min+cenl)/2;
error := true;
GOTO funcend;
end;
if ((cenl - cen) <> 0) then
mlc := (ceny-cenly)/(cen-cenl)
else
Begin
position := (cenl+cen)/2;
error := true;
GOTO funcend;
end;
if ((cenr - cen) <> 0) then
mcr := (cenry-ceny)/(cenr-cen)
else
Begin
position := (cenr+cen)/2;
error := true;
GOTO funcend;
end;
if ((cenr - max) <> 0) then
mrr := (cenry-maxy)/(cenr-max)
else
Begin
position := (cenr+cen)/2;
error := true;
GOTO funcend;
end;
{$ENDIF}
if error then
GOTO funcend;
if (mll*mlc) < 0 then
Begin
discon := true;
dmp := disconrecur(min,cen);
end
else
Begin
if ((mcr*mrr) < 0) then
Begin
discon := true;
dmp := disconrecur(cen,max);
End
else
Begin
error := false;
position := cen;
goto funcend;
End;
End;
funcend:
disconrecur := error or discon;
End;
Begin
discontinuous := disconrecur(min,max);
End;
{----------------------------------------------------------------------------}
Procedure YPlotGraph(Settings : SettingT;
grafiek : grapht;
CalcFunc : CalcFuncT;
form : string);
var
oukleur : word;
outs : TextSettingsType;
nuwedetail : longint;
discontinu : boolean;
def : Record
maxX : single;
maxY : single;
minX : single;
minY : Single;
xunits : single;
rndxu : word;
xusize : single;
End;
i : Integer;
j : longint;
oud,nuut : coordT;
err : integer;
dump : extended;
plotslope : boolean;
dump2 : boolean;
Begin
PlotSlope := (@CalcFunc = @Slope);
OuKleur := GetColor;
GettextSettings(outs);
nuwedetail := settings.detail*settings.skaal;
discontinu := false;
Setcolor(settings.kleur);
LogEvent('Attempting to plot '+form);
If PlotSlope then
LogEvent('Plotting derivative');
With Settings do with grafiek do
Begin
def.maxX := ((maxX - x) DIV skaal)+1;
def.minx := -(x div skaal)-1;
def.maxy := (y div skaal)+1;
def.miny := ((y - maxy) div skaal)-1;
If grafiek.min > def.minx then def.minx := grafiek.min;
If grafiek.max < def.maxX then def.maxX := grafiek.max;
def.xunits := (def.maxX - def.minx);
def.rndxu := Saferound(def.xunits);
def.xusize := def.xunits/def.rndxu;
nuwedetail := Saferound(nuwedetail * def.xusize); { ensure detail is
correct}
{Variables initialized}
If linemode then
Begin
nuut.realx := def.minx;
oud.x := round(x+(nuut.realx*skaal));
oud.realx := def.minx;
nuut.Realy := CalcFunc(nuut.realx,postfix,discontinu);
oud.y := Saferound(y-nuut.realy*skaal);
err := CalcResult;
discontinu := discontinu or (err <> 0);
oud.valid := discontinu;
end; {Start position of graph calculated}
For i := 0 to (def.rndXU-1) do
Begin
For j:= 0 to (nuwedetail -1) do
Begin
nuut.Realx := (def.minx + (i+j/nuwedetail)*def.xusize);
nuut.Realy := CalcFunc(nuut.realx,postfix,dump2);
Err := CalcResult;
nuut.x := round(x+(nuut.realx*skaal));
{ LogEvent('RealX: '+Num2Str(realx)+' Err: '+Int2Str(err));{VERY slow debugging line}
If (err = 0) then
nuut.y := Saferound(y-nuut.realy*skaal);
If linemode then {If connect the dots}
Begin
oud.x := round(x+(oud.realx*skaal));
If discontinu then oud.y := nuut.y; {As vorige keer asimptoot was}
if (err <> 0) then
discontinu := true
else
(* if plotslope then
Begin
{$IFDEF FPC}
try
{$ENDIF}
If (abs(y-calcrealy(nuut.realx,postfix,discontinu)) >= 32767) then
discontinu := true;
if (abs(y-nuut.realy*skaal) >= 10000) then {Prevent overflows}
discontinu := true
{$IFDEF FPC}
except
discontinu := true
End;
{$ENDIF}
End else (* *)
if (abs(y-nuut.realy*skaal) >= 32767) then {Prevent overflows}
discontinu := true
else
discontinu := discontinuous(oud.realx,nuut.realx,
postfix,dump) or dump2;{}
If not discontinu then
Begin
If (nuut.x <> oud.x) or (nuut.y <> oud.y) then {for speed. Will not put same pixel twice}
line(oud.x,oud.y,nuut.x,nuut.y);
nuut.valid := true;
End;
end else
If err = 0 then
Begin
If (nuut.x <> oud.x) or (nuut.y <> oud.y) then {for speed. Will not put same pixel twice}
PutPixel(nuut.x,nuut.y,kleur);
End;{If err =0 /if linemode}
If (oud.x <> nuut.x) then
Begin
PutPixel(nuut.x, maxy, blue);
End;
Oud := nuut;
End; {For j}
End;{for i}
End; {With Settings}
SetColor(0);
Line(0,maxy,maxX,maxy); {Ensure progress indicator is erased}
LogEvent('Plotted '+form);
with outs do
Begin
SetColor(oukleur);
SettextStyle(font,direction,Charsize);
SettextJustify(horiz,vert);
End;
End;
{----------------------------------------------------------------------------}
Function GetScriptLine(Var lr : text;
var linenum : word;
var error : byte) : string;
var
Str : String;
Begin
{$IFDEF EXCEPT}
try
Readln(lr,str);
Inc(linenum);
GetScriptLine := str;
except
LogEvent('Fatal Error reading line '+Int2Str(linenum)+
': Unexpected end of file.');
Error := 99;
GetScriptLine := '';
end;
{$ELSE}
{$I-}Readln(lr,str);{$I+}
Inc(linenum);
GetScriptLine := str;
If IOResult <> 0 then
Begin
LogEvent('Fatal Error reading line '+Int2Str(linenum)+
': Unexpected end of file.');
Error := 99;
GetScriptLine := '';
End;
{$ENDIF}
End;
{----------------------------------------------------------------------------}
Function GetParamCount(const line : string) : byte;
var
i : integer;
antw : byte;
Begin
antw := 0;
For i :=1 to length(line) do
Begin
If (antw = 0) and (line[i] = ' ') then
Inc(antw);
If (line[i] = '|') then
Inc(antw);
End;
GetParamCount := antw;
End;
{----------------------------------------------------------------------------}
Function GetParam(const line : string;no : byte) : String;
var
i : integer;
ts : string;
current : byte;
Begin
current := 0;
ts := '';
For i :=1 to length(line) do
Begin
If (current = 0) and (line[i] = ' ') then
Inc(current);
If (line[i] = '|') then
Inc(current);
If (current = no) then
ts := ts + line[i];
If (current > no) then
exit;
End;
GetParam := ts;
End;
{----------------------------------------------------------------------------}
Function CalcValu (const str : string;
const x,y : Extended;
Var error : boolean) : Extended;
var
postf : PostfT;
Begin
error := false;
{$IFDEF EXCEPT}
try
{$ENDIF}
String2Postf(str, postf);
{$IFDEF EXCEPT}
except
error := true;
CalcValu := 0;
end;
{$ENDIF}
If CalcError <> 0 then
error := true;
If not (error) then
Begin
{$IFDEF EXCEPT}
try
{$ENDIF}
CalcValu := CalcPostfix(postf,x,y,0);
{$IFDEF EXCEPT}
except
error := true;
CalcValu := 0;
End;
{$ENDIF}
If CalcError <> 0 then
error := true;
End;
If Error then
CalcValu := 0;
End;
{----------------------------------------------------------------------------}
Function Scriptplot(Settings : SettingT;filename : string) : byte;
{Error codes:
0 : none
1 : Non- fatal
99 : Fatal
}
Var
oukleur : word;
outs : TextSettingsType;
srp : TEXT;
ioe : integer;
str,ts : String;
error : byte;
i, line : Word;
err : integer;
grafiek : grapht;
li : longint;
ce : integer absolute li;
LineType : Commandt;
boolerr : boolean;
parm : string;
label
readline, {Position of Readln(), used if line is empty}
cleanup; {Program jump daarheen op fatal errors}
Begin
error := 0;
GettextSettings(outs);
ioe := IOResult;
OuKleur := GetColor;
ioe := 0;
LogEvent('Plotting from '+filename+' started');
Case openscript(srp,filename) of
0 : LogEvent('File Opened successfully');
else
Goto Cleanup;
End;
line := 0;
If not(Eof(srp)) then
Begin
str := GetScriptLine(srp,line,error);
if (error = 99) then
GOTO cleanup;
End
else {If not Eof}
Begin
LogEvent('Fatal Error: File Empty.');
Error := 99;
GOTO Cleanup;
End;{else of in not Eof}
LogEvent('Processing line no. '+int2str(line)+' "'+str+'"');
LineType := IDScriptLine(str);
If (LineType <> headerl) then
Begin
LogEvent('Error: Invalid file format.');
Error := 99;
GOTO Cleanup;
End;
Readline:
While not(Eof(srp)) do
Begin
LogEvent('Processing line no. '+int2str(line)+' "'+str+'"');
str := UpperCase(GetScriptLine(srp,line,error));
if (error = 99) then
GOTO cleanup;
If (str = '') then
goto readline;
LineType := IDScriptLine(str);
LogEvent(ScriptLineDescript(LineType));
If LineType = UnknownL then
error := 1;
If (MinParams(LineType) < GetParamCount(str)) then
Begin
LogEvent('Too little parameters for line');
error := 1;
End;
{Up 2 date to here}
Case LineType of
comment : ;{Do nothing}
setcolorl :
Begin
parm := GetParam(str,1);{TODO}
ioe := SafeRound(
ParseString(parm,boolerr,MaxX,MaxY,0)
);
If not(boolerr) then
Begin
Settings.kleur := ioe;
LogEvent('Color set.');
End
else
Begin
LogEvent('Error parsing color');
{ error{}
End;
End;
cls :
Begin
ClearViewPort;
Asse(Settings);
LogEvent('Screen cleared');
End;
setdetail :
Begin
End;
setlinemode :
Begin
End;
setscale :
Begin
End;
setx :
Begin
End;
sety :
Begin
End;
plotx :
Begin
End;
ploty :
Begin
End;
plotxd :
Begin
End;
plotyd :
Begin
End;
putdotl :
Begin
End;
savel :
Begin
End;
loadl :
Begin
End;
pushposl :
Begin
End;
delayl :
Begin
End;
waitl :
Begin
End;
headerl :
Begin
LogEvent('Error: Header not expected here');
error := 1;
End;
else
LogEvent('Invalid Line');
End;
Case str[1] of
';' : ;
'C' : Begin
if str[2] = ' ' then
begin
if length(ts) = 1 then
case ts[1] of
'0' : settings.kleur := 0;
'1' : settings.kleur := 1;
'2' : settings.kleur := 2;
'3' : settings.kleur := 3;
'4' : settings.kleur := 4;
'5' : settings.kleur := 5;
'6' : settings.kleur := 6;
'7' : settings.kleur := 7;
'8' : settings.kleur := 8;
'9' : settings.kleur := 9;
else
LogEvent('Line '+Int2str(line)+' contains an invalid color, '+ts+'.');
end {case}
else {if length}
if (length(ts) = 2) and (ts[1]='1') then
case ts[2] of
'1' : settings.kleur := 11;
'2' : settings.kleur := 12;
'3' : settings.kleur := 13;
'4' : settings.kleur := 14;
'5' : settings.kleur := 15;
else {case}
LogEvent('Line '+Int2str(line)+' contains an invalid color, '+ts+'.');
error := 1;
end;{if length}
end else {if str[2]}
if ((str[1]+str[2]+str[3])= 'CLS') then
begin
GraphMode('screen');
Asse(Settings);
LogEvent('Screen cleared');
end;{if 'cls'}
End; {'C'}
'D' : Begin
val(ts,i,err);
If (err = 0) and (i > 0) then
settings.detail := i
else
Begin
LogEvent('Detail value invalid');
Error := 1;
End;
end; {'D'}
'L' : Begin
If (length(ts) = 1) then
case ts[1] of
'1' : settings.linemode := true;
'0' : settings.linemode := false;
'T' : settings.linemode := not(settings.linemode)
else
error := 1;
LogEvent('Linemode must be set to "1","0" or "T".');
end;{case & if}
end; {'L'}
'S' : Begin
val(ts,i,err);
If (err = 0) and (i > 0) then
settings.skaal := i
else
Begin
LogEvent('Scale value invalid');
Error := 1;
End; {If err = 0}
end; {'S'}
'Y' : Begin
If (ts <> 'C') then
Begin
val(ts,i,err);
If (err = 0) and (i > 0) then
settings.x := i
else
Begin
LogEvent('Y-axis position invalid');
Error := 1;
End;
end else
settings.x := maxX div 2;
end; {'Y'}
'X' : Begin
If (ts <> 'C') then
Begin
val(ts,i,err);
If (err = 0) and (i > 0) then
settings.y := i
else
Begin
LogEvent('X-axis position invalid');
Error := 1;
End;
end else
settings.Y := maxy div 2;
end; {'X'}
'P' : Begin
li := Str2graph(ts,grafiek);
If ce = 0 then
Begin
PrecalcPostfix(grafiek.postfix);
If pcalcexp.calcerror = 0 then
Begin
{$IFDEF FPC}
YPlotGraph(Settings, grafiek,@CalcRealy,ts);
{$ELSE}
YPlotGraph(Settings, grafiek,CalcRealy,ts);
{$ENDIF}
LogEvent('Graph "'+ts+'" plotted');
End else
Begin
LogEvent('Ongeldige vergelyking: "'+ts+'"');
LogEvent('Error '+Int2Str(pcalcexp.calcerror)+': '+pcalcErrorMsg(pcalcexp.calcerror));
Error := 1;
End;
End else
Begin
LogEvent('Ongeldige vergelyking: "'+ts+'"');
LogEvent('Error '+int2Str(ce)+': '+pcalcErrorMsg(ce));
Error := 1;
End;
end; {'P'}
else
LogEvent('Error identifying line.');
if length(str) > 0 then
error := 1;
end; {case str[1] of}
LogEvent('Finished with line '+Int2Str(line));
End; {While not(Eof)}
cleanup:
LogEvent('Plotting completed.');
case error of
0 : LogEvent('No errors encountered');
1 : LogEvent('Non-fatal errors encountered');
99 : LogEvent('Fatal error encountered');
End;
ScriptPlot := Error;
LogEvent('--------------------------------------------------------');
{$IFDEF EXCEPT}
try
Close(srp);
except
LogEvent('Error Closing file "'+filename+'" after plotting.');
end;
{$ELSE}
{$I-}Close(srp);{$I+}
error := IOResult;
{$ENDIF}
with outs do
Begin
SetColor(oukleur);
SettextStyle(font,direction,Charsize);
SettextJustify(horiz,vert);
End;
{$IFNDEF WIN32} {TODO}
If settings.view then readkey;
{$ENDIF}
End;
{----------------------------------------------------------------------------}
Procedure Menu;
{- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -}
Procedure SettingsWindow(Settings : SettingT);
Begin
{$IFNDEF LINUX}
Window(63,10,79,30);
{$ELSE}
Window(63,4,79,24);
{$ENDIF}
TextBackground(Green);
ClrScr;
{$IFNDEF LINUX}
Window(64,11,79,29);
{$ELSE}
Window(64,5,79,24);