97 lines
1.6 KiB
ObjectPascal
97 lines
1.6 KiB
ObjectPascal
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.
|