add 3dplot example, small doc fixes

This commit is contained in:
slederer 2024-11-22 23:52:08 +01:00
parent 7fdbd247e6
commit 4ff6129bc3
2 changed files with 100 additions and 3 deletions

View file

@ -44,7 +44,7 @@ var a:array [1..3] of integer;
... ...
a[1] := 3; a[3] := 2; a[5] := 1; a[1] := 3; a[2] := 2; a[3] := 1;
for i in a do for i in a do
writeln(i); writeln(i);
@ -66,7 +66,7 @@ var c:char;
``` ```
In Tridora Pascal, this syntax also works because `[ 'y', 'n' ]` will not be treated as a set literal, but as an array literal. In Tridora Pascal, this syntax also works because `[ 'y', 'n' ]` will not be treated as a set literal, but as an array literal.
The _in_ operator also works for linear arrays, so the _if_ statement will have the same result. The _in_ operator also works for linear arrays, so the above _if_ statement will have the same result.
Note that the array _in_ operator will be more inefficient for larger ranges (i.e. `'A'..'z'`), but more efficient for sparse sets (i.e. `'A','z'`). Note that the array _in_ operator will be more inefficient for larger ranges (i.e. `'A'..'z'`), but more efficient for sparse sets (i.e. `'A','z'`).
@ -123,7 +123,7 @@ The implementation also has the following properties:
- _read_/_write_ do ASCII conversion on scalar variables, records and arrays are processed as binary - _read_/_write_ do ASCII conversion on scalar variables, records and arrays are processed as binary
- enums and booleans are treated as integers - enums and booleans are treated as integers
- _readln_/_writeln_ operate as expected, that is, they perform _read_/_write_ and then wait for/write a newline sequence - _readln_/_writeln_ operate as expected, that is, they perform _read_/_write_ and then wait for/write a newline sequence
- other file operations available are _eof_, _eoln_ and _seek_ - other file operations available are _eof_, _eoln_, _seek_ and _filepos_
- for error handling there is a function _IOResult_ - for error handling there is a function _IOResult_
- terminating the program without calling _close_ on open files will lose data - terminating the program without calling _close_ on open files will lose data

97
examples/3dplot.pas Normal file
View file

@ -0,0 +1,97 @@
program threedeeplot;
const w = 640;
h = 400;
var u0,v0:integer;
function fun(x0,y0:real):real;
const vscale = 50.0;
hscale = 20.0;
var x,y,f:real;
begin
x := x0 / hscale;
y := y0 / hscale;
f := sin(sqrt(x*x + y*y));
fun := f * vscale;
end;
procedure plot;
var maxV,minV:array [0..w] of real;
shift:integer;
x,y,z:integer;
lastZ:integer;
numLines:integer;
i:integer;
u,v,lastU,lastV:integer;
color:integer;
procedure resetCurve;
begin
lastU := -1;
lastV := -1;
end;
begin
for i := 0 to w do
begin
maxV[i] := -10000;
minV[i] := 10000;
end;
color := 1;
shift := 4;
x := 0;
numLines := 80;
u0 := w div 2;
v0 := h div 2;
for i := -(numLines div 2) to numLines do
begin
resetCurve;
x := i * (w div numLines);
for y := -w to w do
begin
z := round(fun(x,y));
u := round(y + u0 + i * shift);
v := round(-z + v0 - i * shift);
if (u >= 0) and (u < w) then
begin
if (v < maxV[u]) and (v > minV[u]) then
resetCurve
else
begin
if (u >= 0) and (u < w) and (v > maxV[u]) then
maxV[u] := v;
if (u >= 0) and (u < w) and (v < minV[u]) then
minV[u] := v;
if lastZ < z then
color := 8
else
color := 1;
if (u >= w) or (u < 0) or (v >= h) or (v < 0) then
resetCurve
else
begin
if lastU = -1 then
putpixel(u,v,color)
else
drawline(lastU,lastV,u,v,color);
end;
lastU := u;
lastV := v;
lastZ := z;
end;
end;
end;
end;
end;
begin
initgraphics;
plot;
end.